• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
5  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
6  * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #ifndef _USB_IOCTL_H_
31 #define	_USB_IOCTL_H_
32 
33 #include <linux/ioctl.h>
34 
35 #define	USB_DEVICE_NAME "usbctl"
36 #define	USB_DEVICE_DIR "/dev/usb"
37 #define	USB_GENERIC_NAME "ugen"
38 #define	USB_TEMPLATE_SYSCTL "hw.usb.template"	/* integer type */
39 
40 /*
41  * Align IOCTL structures to hide differences when running 32-bit
42  * programs under 64-bit kernels:
43  */
44 #ifdef COMPAT_32BIT
45 #define	USB_IOCTL_STRUCT_ALIGN(n) __aligned(n)
46 #else
47 #define	USB_IOCTL_STRUCT_ALIGN(n)
48 #endif
49 
50 /* Definition of valid template sysctl values */
51 
52 enum {
53 	USB_TEMP_MSC,		/* USB Mass Storage */
54 	USB_TEMP_CDCE,		/* USB CDC Ethernet */
55 	USB_TEMP_MTP,		/* Message Transfer Protocol */
56 	USB_TEMP_MODEM,		/* USB CDC Modem */
57 	USB_TEMP_AUDIO,		/* USB Audio */
58 	USB_TEMP_KBD,		/* USB Keyboard */
59 	USB_TEMP_MOUSE,		/* USB Mouse */
60 	USB_TEMP_PHONE,		/* USB Phone */
61 	USB_TEMP_SERIALNET,	/* USB CDC Ethernet and Modem */
62 	USB_TEMP_MIDI,		/* USB MIDI */
63 	USB_TEMP_MULTI,		/* USB Ethernet, serial, and storage */
64 	USB_TEMP_CDCEEM,	/* USB Ethernet Emulation Model */
65 	USB_TEMP_MAX,
66 };
67 
68 struct usb_read_dir {
69 #ifdef COMPAT_32BIT
70 	uint64_t urd_data;
71 #else
72 	void   *urd_data;
73 #endif
74 	uint32_t urd_startentry;
75 	uint32_t urd_maxlen;
76 } USB_IOCTL_STRUCT_ALIGN(8);
77 
78 struct usb_ctl_request {
79 #ifdef COMPAT_32BIT
80 	uint64_t ucr_data;
81 #else
82 	void   *ucr_data;
83 #endif
84 	uint16_t ucr_flags;
85 	uint16_t ucr_actlen;		/* actual length transferred */
86 	uint8_t	ucr_addr;		/* zero - currently not used */
87 	struct usb_device_request ucr_request;
88 } USB_IOCTL_STRUCT_ALIGN(8);
89 
90 struct usb_alt_interface {
91 	uint8_t	uai_interface_index;
92 	uint8_t	uai_alt_index;
93 } USB_IOCTL_STRUCT_ALIGN(1);
94 
95 struct usb_gen_descriptor {
96 #ifdef COMPAT_32BIT
97 	uint64_t ugd_data;
98 #else
99 	void   *ugd_data;
100 #endif
101 	uint16_t ugd_lang_id;
102 	uint16_t ugd_maxlen;
103 	uint16_t ugd_actlen;
104 	uint16_t ugd_offset;
105 	uint8_t	ugd_config_index;
106 	uint8_t	ugd_string_index;
107 	uint8_t	ugd_iface_index;
108 	uint8_t	ugd_altif_index;
109 	uint8_t	ugd_endpt_index;
110 	uint8_t	ugd_report_type;
111 	uint8_t	reserved[8];
112 } USB_IOCTL_STRUCT_ALIGN(8);
113 
114 struct usb_device_info {
115 	uint16_t udi_productNo;
116 	uint16_t udi_vendorNo;
117 	uint16_t udi_releaseNo;
118 	uint16_t udi_power;		/* power consumption in mA, 0 if
119 					 * selfpowered */
120 	uint8_t	udi_bus;
121 	uint8_t	udi_addr;		/* device address */
122 	uint8_t	udi_index;		/* device index */
123 	uint8_t	udi_class;
124 	uint8_t	udi_subclass;
125 	uint8_t	udi_protocol;
126 	uint8_t	udi_config_no;		/* current config number */
127 	uint8_t	udi_config_index;	/* current config index */
128 	uint8_t	udi_speed;		/* see "USB_SPEED_XXX" */
129 	uint8_t	udi_mode;		/* see "USB_MODE_XXX" */
130 	uint8_t	udi_nports;
131 	uint8_t	udi_hubaddr;		/* parent HUB address */
132 	uint8_t	udi_hubindex;		/* parent HUB device index */
133 	uint8_t	udi_hubport;		/* parent HUB port */
134 	uint8_t	udi_power_mode;		/* see "USB_POWER_MODE_XXX" */
135 	uint8_t	udi_suspended;		/* set if device is suspended */
136 	uint8_t	udi_reserved[16];	/* leave space for the future */
137 	char	udi_product[128];
138 	char	udi_vendor[128];
139 	char	udi_serial[64];
140 	char	udi_release[8];
141 } USB_IOCTL_STRUCT_ALIGN(2);
142 
143 #define	USB_DEVICE_PORT_PATH_MAX 32
144 
145 struct usb_device_port_path {
146 	uint8_t udp_bus;		/* which bus we are on */
147 	uint8_t udp_index;		/* which device index */
148 	uint8_t udp_port_level;		/* how many levels: 0, 1, 2 ... */
149 	uint8_t udp_port_no[USB_DEVICE_PORT_PATH_MAX];
150 } USB_IOCTL_STRUCT_ALIGN(1);
151 
152 struct usb_device_stats {
153 	uint32_t uds_requests_ok[4];	/* Indexed by transfer type UE_XXX */
154 	uint32_t uds_requests_fail[4];	/* Indexed by transfer type UE_XXX */
155 } USB_IOCTL_STRUCT_ALIGN(4);
156 
157 struct usb_fs_start {
158 	uint8_t	ep_index;
159 } USB_IOCTL_STRUCT_ALIGN(1);
160 
161 struct usb_fs_stop {
162 	uint8_t	ep_index;
163 } USB_IOCTL_STRUCT_ALIGN(1);
164 
165 struct usb_fs_complete {
166 	uint8_t	ep_index;
167 } USB_IOCTL_STRUCT_ALIGN(1);
168 
169 /* This structure is used for all endpoint types */
170 struct usb_fs_endpoint {
171 	/*
172 	 * NOTE: isochronous USB transfer only use one buffer, but can have
173 	 * multiple frame lengths !
174 	 */
175 #ifdef COMPAT_32BIT
176 	uint64_t ppBuffer;
177 	uint64_t pLength;
178 #else
179 	void  **ppBuffer;		/* pointer to userland buffers */
180 	uint32_t *pLength;		/* pointer to frame lengths, updated
181 					 * to actual length */
182 #endif
183 	uint32_t nFrames;		/* number of frames */
184 	uint32_t aFrames;		/* actual number of frames */
185 	uint16_t flags;
186 	/* a single short frame will terminate */
187 #define	USB_FS_FLAG_SINGLE_SHORT_OK 0x0001
188 	/* multiple short frames are allowed */
189 #define	USB_FS_FLAG_MULTI_SHORT_OK 0x0002
190 	/* all frame(s) transmitted are short terminated */
191 #define	USB_FS_FLAG_FORCE_SHORT 0x0004
192 	/* will do a clear-stall before xfer */
193 #define	USB_FS_FLAG_CLEAR_STALL 0x0008
194 	uint16_t timeout;		/* in milliseconds */
195 	/* isocronous completion time in milliseconds - used for echo cancel */
196 	uint16_t isoc_time_complete;
197 	/* timeout value for no timeout */
198 #define	USB_FS_TIMEOUT_NONE 0
199 	int	status;			/* see USB_ERR_XXX */
200 } USB_IOCTL_STRUCT_ALIGN(8);
201 
202 struct usb_fs_init {
203 	/* userland pointer to endpoints structure */
204 #ifdef COMPAT_32BIT
205 	uint64_t pEndpoints;
206 #else
207 	struct usb_fs_endpoint *pEndpoints;
208 #endif
209 	/* maximum number of endpoints */
210 	uint8_t	ep_index_max;
211 } USB_IOCTL_STRUCT_ALIGN(8);
212 
213 struct usb_fs_uninit {
214 	uint8_t	dummy;			/* zero */
215 } USB_IOCTL_STRUCT_ALIGN(1);
216 
217 struct usb_fs_open {
218 #define	USB_FS_MAX_BUFSIZE (1 << 25)	/* 32 MBytes */
219 	uint32_t max_bufsize;
220 #define	USB_FS_MAX_FRAMES		(1U << 12)
221 #define	USB_FS_MAX_FRAMES_PRE_SCALE	(1U << 31)	/* for ISOCHRONOUS transfers */
222 	uint32_t max_frames;		/* read and write */
223 	uint16_t max_packet_length;	/* read only */
224 	uint8_t	dev_index;		/* currently unused */
225 	uint8_t	ep_index;
226 	uint8_t	ep_no;			/* bEndpointNumber */
227 } USB_IOCTL_STRUCT_ALIGN(4);
228 
229 struct usb_fs_open_stream {
230 	struct usb_fs_open fs_open;
231 	uint16_t stream_id;		/* stream ID */
232 } USB_IOCTL_STRUCT_ALIGN(4);
233 
234 struct usb_fs_close {
235 	uint8_t	ep_index;
236 } USB_IOCTL_STRUCT_ALIGN(1);
237 
238 struct usb_fs_clear_stall_sync {
239 	uint8_t	ep_index;
240 } USB_IOCTL_STRUCT_ALIGN(1);
241 
242 struct usb_gen_quirk {
243 	uint16_t index;			/* Quirk Index */
244 	uint16_t vid;			/* Vendor ID */
245 	uint16_t pid;			/* Product ID */
246 	uint16_t bcdDeviceLow;		/* Low Device Revision */
247 	uint16_t bcdDeviceHigh;		/* High Device Revision */
248 	uint16_t reserved[2];
249 	/*
250 	 * String version of quirk including terminating zero. See
251 	 * UQ_XXX in "usb_quirk.h".
252 	 */
253 	char	quirkname[64 - 14];
254 } USB_IOCTL_STRUCT_ALIGN(2);
255 
256 /* USB controller */
257 #define	USB_REQUEST		_IOWR('U', 1, struct usb_ctl_request)
258 #define	USB_SETDEBUG		_IOW ('U', 2, int)
259 #define	USB_DISCOVER		_IO  ('U', 3)
260 #define	USB_DEVICEINFO		_IOWR('U', 4, struct usb_device_info)
261 #define	USB_DEVICESTATS		_IOR ('U', 5, struct usb_device_stats)
262 #define	USB_DEVICEENUMERATE	_IOW ('U', 6, int)
263 
264 /* Generic HID device. Numbers 26 and 30-39 are occupied by hidraw. */
265 #define	USB_GET_REPORT_DESC	_IOWR('U', 21, struct usb_gen_descriptor)
266 #define	USB_SET_IMMED		_IOW ('U', 22, int)
267 #define	USB_GET_REPORT		_IOWR('U', 23, struct usb_gen_descriptor)
268 #define	USB_SET_REPORT		_IOW ('U', 24, struct usb_gen_descriptor)
269 #define	USB_GET_REPORT_ID	_IOR ('U', 25, int)
270 
271 /* Generic USB device */
272 #define	USB_GET_CONFIG		_IOR ('U', 100, int)
273 #define	USB_SET_CONFIG		_IOW ('U', 101, int)
274 #define	USB_GET_ALTINTERFACE	_IOWR('U', 102, struct usb_alt_interface)
275 #define	USB_SET_ALTINTERFACE	_IOWR('U', 103, struct usb_alt_interface)
276 #define	USB_GET_DEVICE_DESC	_IOR ('U', 105, struct usb_device_descriptor)
277 #define	USB_GET_CONFIG_DESC	_IOR ('U', 106, struct usb_config_descriptor)
278 #define	USB_GET_RX_INTERFACE_DESC _IOR ('U', 107, struct usb_interface_descriptor)
279 #define	USB_GET_RX_ENDPOINT_DESC _IOR ('U', 108, struct usb_endpoint_descriptor)
280 #define	USB_GET_FULL_DESC	_IOWR('U', 109, struct usb_gen_descriptor)
281 #define	USB_GET_STRING_DESC	_IOWR('U', 110, struct usb_gen_descriptor)
282 #define	USB_DO_REQUEST		_IOWR('U', 111, struct usb_ctl_request)
283 #define	USB_GET_DEVICEINFO	_IOR ('U', 112, struct usb_device_info)
284 #define	USB_SET_RX_SHORT_XFER	_IOW ('U', 113, int)
285 #define	USB_SET_RX_TIMEOUT	_IOW ('U', 114, int)
286 #define	USB_GET_RX_FRAME_SIZE	_IOR ('U', 115, int)
287 #define	USB_GET_RX_BUFFER_SIZE	_IOR ('U', 117, int)
288 #define	USB_SET_RX_BUFFER_SIZE	_IOW ('U', 118, int)
289 #define	USB_SET_RX_STALL_FLAG	_IOW ('U', 119, int)
290 #define	USB_SET_TX_STALL_FLAG	_IOW ('U', 120, int)
291 #define	USB_GET_IFACE_DRIVER	_IOWR('U', 121, struct usb_gen_descriptor)
292 #define	USB_CLAIM_INTERFACE	_IOW ('U', 122, int)
293 #define	USB_RELEASE_INTERFACE	_IOW ('U', 123, int)
294 #define	USB_IFACE_DRIVER_ACTIVE	_IOW ('U', 124, int)
295 #define	USB_IFACE_DRIVER_DETACH	_IOW ('U', 125, int)
296 #define	USB_GET_PLUGTIME	_IOR ('U', 126, uint32_t)
297 #define	USB_READ_DIR		_IOW ('U', 127, struct usb_read_dir)
298 /* 128 - 133 unused */
299 #define	USB_GET_DEV_PORT_PATH	_IOR ('U', 134, struct usb_device_port_path)
300 #define	USB_GET_POWER_USAGE	_IOR ('U', 135, int)
301 #define	USB_SET_TX_FORCE_SHORT	_IOW ('U', 136, int)
302 #define	USB_SET_TX_TIMEOUT	_IOW ('U', 137, int)
303 #define	USB_GET_TX_FRAME_SIZE	_IOR ('U', 138, int)
304 #define	USB_GET_TX_BUFFER_SIZE	_IOR ('U', 139, int)
305 #define	USB_SET_TX_BUFFER_SIZE	_IOW ('U', 140, int)
306 #define	USB_GET_TX_INTERFACE_DESC _IOR ('U', 141, struct usb_interface_descriptor)
307 #define	USB_GET_TX_ENDPOINT_DESC _IOR ('U', 142, struct usb_endpoint_descriptor)
308 #define	USB_SET_PORT_ENABLE	_IOW ('U', 143, int)
309 #define	USB_SET_PORT_DISABLE	_IOW ('U', 144, int)
310 #define	USB_SET_POWER_MODE	_IOW ('U', 145, int)
311 #define	USB_GET_POWER_MODE	_IOR ('U', 146, int)
312 #define	USB_SET_TEMPLATE	_IOW ('U', 147, int)
313 #define	USB_GET_TEMPLATE	_IOR ('U', 148, int)
314 
315 /* Modem device */
316 #define	USB_GET_CM_OVER_DATA	_IOR ('U', 180, int)
317 #define	USB_SET_CM_OVER_DATA	_IOW ('U', 181, int)
318 
319 /* GPIO control */
320 #define	USB_GET_GPIO		_IOR ('U', 182, int)
321 #define	USB_SET_GPIO		_IOW ('U', 183, int)
322 
323 /* USB file system interface */
324 #define	USB_FS_START		_IOW ('U', 192, struct usb_fs_start)
325 #define	USB_FS_STOP		_IOW ('U', 193, struct usb_fs_stop)
326 #define	USB_FS_COMPLETE		_IOR ('U', 194, struct usb_fs_complete)
327 #define	USB_FS_INIT		_IOW ('U', 195, struct usb_fs_init)
328 #define	USB_FS_UNINIT		_IOW ('U', 196, struct usb_fs_uninit)
329 #define	USB_FS_OPEN		_IOWR('U', 197, struct usb_fs_open)
330 #define	USB_FS_CLOSE		_IOW ('U', 198, struct usb_fs_close)
331 #define	USB_FS_CLEAR_STALL_SYNC _IOW ('U', 199, struct usb_fs_clear_stall_sync)
332 #define	USB_FS_OPEN_STREAM	_IOWR('U', 200, struct usb_fs_open_stream)
333 
334 /* USB quirk system interface */
335 #define	USB_DEV_QUIRK_GET	_IOWR('Q', 0, struct usb_gen_quirk)
336 #define	USB_QUIRK_NAME_GET	_IOWR('Q', 1, struct usb_gen_quirk)
337 #define	USB_DEV_QUIRK_ADD	_IOW ('Q', 2, struct usb_gen_quirk)
338 #define	USB_DEV_QUIRK_REMOVE	_IOW ('Q', 3, struct usb_gen_quirk)
339 
340 #endif					/* _USB_IOCTL_H_ */
341