1 // Copyright 2019 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Translated from include/uapi/linux/usbdevice_fs.h 6 7 #![allow(non_upper_case_globals)] 8 #![allow(non_camel_case_types)] 9 #![allow(non_snake_case)] 10 11 use std::os::raw::{c_char, c_int, c_uchar, c_uint, c_void}; 12 13 use base::{ioctl_io_nr, ioctl_ior_nr, ioctl_iow_nr, ioctl_iowr_nr}; 14 15 #[repr(C)] 16 #[derive(Default)] 17 pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>); 18 impl<T> __IncompleteArrayField<T> { 19 #[inline] new() -> Self20 pub fn new() -> Self { 21 __IncompleteArrayField(::std::marker::PhantomData) 22 } 23 #[inline] as_ptr(&self) -> *const T24 pub unsafe fn as_ptr(&self) -> *const T { 25 ::std::mem::transmute(self) 26 } 27 #[inline] as_mut_ptr(&mut self) -> *mut T28 pub unsafe fn as_mut_ptr(&mut self) -> *mut T { 29 ::std::mem::transmute(self) 30 } 31 #[inline] as_slice(&self, len: usize) -> &[T]32 pub unsafe fn as_slice(&self, len: usize) -> &[T] { 33 ::std::slice::from_raw_parts(self.as_ptr(), len) 34 } 35 #[inline] as_mut_slice(&mut self, len: usize) -> &mut [T]36 pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { 37 ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) 38 } 39 } 40 impl<T> ::std::clone::Clone for __IncompleteArrayField<T> { 41 #[inline] clone(&self) -> Self42 fn clone(&self) -> Self { 43 Self::new() 44 } 45 } 46 47 #[repr(C)] 48 #[derive(Copy, Clone)] 49 pub struct usbdevfs_ctrltransfer { 50 pub bRequestType: u8, 51 pub bRequest: u8, 52 pub wValue: u16, 53 pub wIndex: u16, 54 pub wLength: u16, 55 pub timeout: u32, 56 pub data: *mut c_void, 57 } 58 59 #[repr(C)] 60 #[derive(Copy, Clone)] 61 pub struct usbdevfs_bulktransfer { 62 pub ep: c_uint, 63 pub len: c_uint, 64 pub timeout: c_uint, 65 pub data: *mut c_void, 66 } 67 68 #[repr(C)] 69 #[derive(Default, Copy, Clone)] 70 pub struct usbdevfs_setinterface { 71 pub interface: c_uint, 72 pub altsetting: c_uint, 73 } 74 75 #[repr(C)] 76 #[derive(Default, Copy, Clone)] 77 struct usbdevfs_disconnectsignal { 78 pub signr: c_uint, 79 pub context: usize, 80 } 81 82 pub const USBDEVFS_MAXDRIVERNAME: usize = 255; 83 84 #[repr(C)] 85 #[derive(Copy, Clone)] 86 pub struct usbdevfs_getdriver { 87 pub interface: c_uint, 88 pub driver: [u8; USBDEVFS_MAXDRIVERNAME + 1], 89 } 90 91 #[repr(C)] 92 #[derive(Default, Copy, Clone)] 93 pub struct usbdevfs_connectinfo { 94 pub devnum: c_uint, 95 pub slow: c_char, 96 } 97 98 pub const USBDEVFS_URB_SHORT_NOT_OK: c_uint = 0x01; 99 pub const USBDEVFS_URB_ISO_ASAP: c_uint = 0x02; 100 pub const USBDEVFS_URB_BULK_CONTINUATION: c_uint = 0x04; 101 pub const USBDEVFS_URB_NO_FSBR: c_uint = 0x20; 102 pub const USBDEVFS_URB_ZERO_PACKET: c_uint = 0x40; 103 pub const USBDEVFS_URB_NO_INTERRUPT: c_uint = 0x80; 104 105 pub const USBDEVFS_URB_TYPE_ISO: c_uchar = 0; 106 pub const USBDEVFS_URB_TYPE_INTERRUPT: c_uchar = 1; 107 pub const USBDEVFS_URB_TYPE_CONTROL: c_uchar = 2; 108 pub const USBDEVFS_URB_TYPE_BULK: c_uchar = 3; 109 110 #[repr(C)] 111 #[derive(Default, Copy, Clone)] 112 pub struct usbdevfs_iso_packet_desc { 113 pub length: c_uint, 114 pub actual_length: c_uint, 115 pub status: c_uint, 116 } 117 118 #[repr(C)] 119 #[derive(Clone)] 120 pub struct usbdevfs_urb { 121 pub urb_type: c_uchar, 122 pub endpoint: c_uchar, 123 pub status: c_int, 124 pub flags: c_uint, 125 pub buffer: *mut c_void, 126 pub buffer_length: c_int, 127 pub actual_length: c_int, 128 pub start_frame: c_int, 129 pub number_of_packets_or_stream_id: c_uint, 130 pub error_count: c_int, 131 pub signr: c_uint, 132 pub usercontext: usize, 133 pub iso_frame_desc: __IncompleteArrayField<usbdevfs_iso_packet_desc>, 134 } 135 136 impl Default for usbdevfs_urb { default() -> Self137 fn default() -> Self { 138 unsafe { ::std::mem::zeroed() } 139 } 140 } 141 142 // The structure that embeds this should ensure that this is safe. 143 unsafe impl Send for usbdevfs_urb {} 144 unsafe impl Sync for usbdevfs_urb {} 145 146 #[repr(C)] 147 #[derive(Copy, Clone)] 148 pub struct usbdevfs_ioctl { 149 pub ifno: c_int, 150 pub ioctl_code: c_int, 151 pub data: *mut c_void, 152 } 153 154 #[repr(C)] 155 #[derive(Copy, Clone)] 156 pub struct usbdevfs_hub_portinfo { 157 pub nports: c_char, 158 pub port: [u8; 127], 159 } 160 161 pub const USBDEVFS_CAP_ZERO_PACKET: u32 = 0x01; 162 pub const USBDEVFS_CAP_BULK_CONTINUATION: u32 = 0x02; 163 pub const USBDEVFS_CAP_NO_PACKET_SIZE_LIM: u32 = 0x04; 164 pub const USBDEVFS_CAP_BULK_SCATTER_GATHER: u32 = 0x08; 165 pub const USBDEVFS_CAP_REAP_AFTER_DISCONNECT: u32 = 0x10; 166 pub const USBDEVFS_CAP_MMAP: u32 = 0x20; 167 pub const USBDEVFS_CAP_DROP_PRIVILEGES: u32 = 0x40; 168 169 pub const USBDEVFS_DISCONNECT_CLAIM_IF_DRIVER: c_uint = 0x01; 170 pub const USBDEVFS_DISCONNECT_CLAIM_EXCEPT_DRIVER: c_uint = 0x02; 171 172 #[repr(C)] 173 #[derive(Copy, Clone)] 174 pub struct usbdevfs_disconnect_claim { 175 pub interface: c_uint, 176 pub flags: c_uint, 177 pub driver: [u8; USBDEVFS_MAXDRIVERNAME + 1], 178 } 179 180 #[repr(C)] 181 pub struct usbdevfs_streams { 182 pub num_streams: c_uint, 183 pub num_eps: c_uint, 184 pub eps: __IncompleteArrayField<c_char>, 185 } 186 187 const U: u32 = 'U' as u32; 188 189 ioctl_iowr_nr!(USBDEVFS_CONTROL, U, 0, usbdevfs_ctrltransfer); 190 ioctl_iowr_nr!(USBDEVFS_BULK, U, 2, usbdevfs_bulktransfer); 191 ioctl_ior_nr!(USBDEVFS_RESETEP, U, 3, c_uint); 192 ioctl_ior_nr!(USBDEVFS_SETINTERFACE, U, 4, usbdevfs_setinterface); 193 ioctl_ior_nr!(USBDEVFS_SETCONFIGURATION, U, 5, c_uint); 194 ioctl_ior_nr!(USBDEVFS_GETDRIVER, U, 8, usbdevfs_getdriver); 195 ioctl_ior_nr!(USBDEVFS_SUBMITURB, U, 10, usbdevfs_urb); 196 ioctl_io_nr!(USBDEVFS_DISCARDURB, U, 11); 197 ioctl_iow_nr!(USBDEVFS_REAPURB, U, 12, *mut *mut usbdevfs_urb); 198 ioctl_iow_nr!(USBDEVFS_REAPURBNDELAY, U, 13, *mut *mut usbdevfs_urb); 199 ioctl_ior_nr!(USBDEVFS_DISCSIGNAL, U, 14, usbdevfs_disconnectsignal); 200 ioctl_ior_nr!(USBDEVFS_CLAIMINTERFACE, U, 15, c_uint); 201 ioctl_ior_nr!(USBDEVFS_RELEASEINTERFACE, U, 16, c_uint); 202 ioctl_iow_nr!(USBDEVFS_CONNECTINFO, U, 17, usbdevfs_connectinfo); 203 ioctl_iowr_nr!(USBDEVFS_IOCTL, U, 18, usbdevfs_ioctl); 204 ioctl_ior_nr!(USBDEVFS_HUB_PORTINFO, U, 19, usbdevfs_hub_portinfo); 205 ioctl_io_nr!(USBDEVFS_RESET, U, 20); 206 ioctl_ior_nr!(USBDEVFS_CLEAR_HALT, U, 21, c_uint); 207 ioctl_io_nr!(USBDEVFS_DISCONNECT, U, 22); 208 ioctl_io_nr!(USBDEVFS_CONNECT, U, 23); 209 ioctl_ior_nr!(USBDEVFS_CLAIM_PORT, U, 24, c_uint); 210 ioctl_ior_nr!(USBDEVFS_RELEASE_PORT, U, 25, c_uint); 211 ioctl_ior_nr!(USBDEVFS_GET_CAPABILITIES, U, 26, u32); 212 ioctl_ior_nr!(USBDEVFS_DISCONNECT_CLAIM, U, 27, usbdevfs_disconnect_claim); 213 ioctl_ior_nr!(USBDEVFS_ALLOC_STREAMS, U, 28, usbdevfs_streams); 214 ioctl_ior_nr!(USBDEVFS_FREE_STREAMS, U, 29, usbdevfs_streams); 215 ioctl_iow_nr!(USBDEVFS_DROP_PRIVILEGES, U, 30, u32); 216 ioctl_io_nr!(USBDEVFS_GET_SPEED, U, 31); 217