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