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