1/*
2 * usbfs header structures
3 * Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
4 * Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef __LIBUSB_USBFS_H__
22#define __LIBUSB_USBFS_H__
23
24#include <linux/version.h>
25
26#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
27 #define SYSFS_DEVICE_PATH "/sys/bus/usb/devices"
28#else
29 #define SYSFS_DEVICE_PATH "/proc/bus/usb/devices"
30#endif
31
32struct usbfs_ctrltransfer {
33	/* keep in sync with usbdevice_fs.h:usbdevfs_ctrltransfer */
34	uint8_t  bmRequestType;
35	uint8_t  bRequest;
36	uint16_t wValue;
37	uint16_t wIndex;
38	uint16_t wLength;
39
40	uint32_t timeout;	/* in milliseconds */
41
42	/* pointer to data */
43	void *data;
44};
45
46struct usbfs_bulktransfer {
47	/* keep in sync with usbdevice_fs.h:usbdevfs_bulktransfer */
48	unsigned int ep;
49	unsigned int len;
50	unsigned int timeout;	/* in milliseconds */
51
52	/* pointer to data */
53	void *data;
54};
55
56struct usbfs_setinterface {
57	/* keep in sync with usbdevice_fs.h:usbdevfs_setinterface */
58	unsigned int interface;
59	unsigned int altsetting;
60};
61
62#define USBFS_MAXDRIVERNAME 255
63
64struct usbfs_getdriver {
65	unsigned int interface;
66	char driver[USBFS_MAXDRIVERNAME + 1];
67};
68
69#define USBFS_URB_SHORT_NOT_OK		0x01
70#define USBFS_URB_ISO_ASAP			0x02
71#define USBFS_URB_BULK_CONTINUATION	0x04
72#define USBFS_URB_QUEUE_BULK		0x10
73
74enum usbfs_urb_type {
75	USBFS_URB_TYPE_ISO = 0,
76	USBFS_URB_TYPE_INTERRUPT = 1,
77	USBFS_URB_TYPE_CONTROL = 2,
78	USBFS_URB_TYPE_BULK = 3,
79};
80
81struct usbfs_iso_packet_desc {
82	unsigned int length;
83	unsigned int actual_length;
84	unsigned int status;
85};
86
87#define MAX_ISO_BUFFER_LENGTH		32768
88#define MAX_BULK_BUFFER_LENGTH		16384
89#define MAX_CTRL_BUFFER_LENGTH		4096
90
91struct usbfs_urb {
92	unsigned char type;
93	unsigned char endpoint;
94	int status;
95	unsigned int flags;
96	void *buffer;
97	int buffer_length;
98	int actual_length;
99	int start_frame;
100	int number_of_packets;
101	int error_count;
102	unsigned int signr;
103	void *usercontext;
104	struct usbfs_iso_packet_desc iso_frame_desc[0];
105};
106
107struct usbfs_connectinfo {
108	unsigned int devnum;
109	unsigned char slow;
110};
111
112struct usbfs_ioctl {
113	int ifno;	/* interface 0..N ; negative numbers reserved */
114	int ioctl_code;	/* MUST encode size + direction of data so the
115			 * macros in <asm/ioctl.h> give correct values */
116	void *data;	/* param buffer (in, or out) */
117};
118
119struct usbfs_hub_portinfo {
120	unsigned char numports;
121	unsigned char port[127];	/* port to device num mapping */
122};
123
124#define IOCTL_USBFS_CONTROL	_IOWR('U', 0, struct usbfs_ctrltransfer)
125#define IOCTL_USBFS_BULK		_IOWR('U', 2, struct usbfs_bulktransfer)
126#define IOCTL_USBFS_RESETEP	_IOR('U', 3, unsigned int)
127#define IOCTL_USBFS_SETINTF	_IOR('U', 4, struct usbfs_setinterface)
128#define IOCTL_USBFS_SETCONFIG	_IOR('U', 5, unsigned int)
129#define IOCTL_USBFS_GETDRIVER	_IOW('U', 8, struct usbfs_getdriver)
130#define IOCTL_USBFS_SUBMITURB	_IOR('U', 10, struct usbfs_urb)
131#define IOCTL_USBFS_DISCARDURB	_IO('U', 11)
132#define IOCTL_USBFS_REAPURB	_IOW('U', 12, void *)
133#define IOCTL_USBFS_REAPURBNDELAY	_IOW('U', 13, void *)
134#define IOCTL_USBFS_CLAIMINTF	_IOR('U', 15, unsigned int)
135#define IOCTL_USBFS_RELEASEINTF	_IOR('U', 16, unsigned int)
136#define IOCTL_USBFS_CONNECTINFO	_IOW('U', 17, struct usbfs_connectinfo)
137#define IOCTL_USBFS_IOCTL         _IOWR('U', 18, struct usbfs_ioctl)
138#define IOCTL_USBFS_HUB_PORTINFO	_IOR('U', 19, struct usbfs_hub_portinfo)
139#define IOCTL_USBFS_RESET		_IO('U', 20)
140#define IOCTL_USBFS_CLEAR_HALT	_IOR('U', 21, unsigned int)
141#define IOCTL_USBFS_DISCONNECT	_IO('U', 22)
142#define IOCTL_USBFS_CONNECT	_IO('U', 23)
143
144#endif
145