Home | History | Annotate | Download | only in os
      1 /*
      2  * usbfs header structures
      3  * Copyright  2007 Daniel Drake <dsd (at) gentoo.org>
      4  * Copyright  2001 Johannes Erdfelt <johannes (at) 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/types.h>
     25 
     26 #define SYSFS_DEVICE_PATH "/sys/bus/usb/devices"
     27 
     28 struct usbfs_ctrltransfer {
     29 	/* keep in sync with usbdevice_fs.h:usbdevfs_ctrltransfer */
     30 	uint8_t  bmRequestType;
     31 	uint8_t  bRequest;
     32 	uint16_t wValue;
     33 	uint16_t wIndex;
     34 	uint16_t wLength;
     35 
     36 	uint32_t timeout;	/* in milliseconds */
     37 
     38 	/* pointer to data */
     39 	void *data;
     40 };
     41 
     42 struct usbfs_bulktransfer {
     43 	/* keep in sync with usbdevice_fs.h:usbdevfs_bulktransfer */
     44 	unsigned int ep;
     45 	unsigned int len;
     46 	unsigned int timeout;	/* in milliseconds */
     47 
     48 	/* pointer to data */
     49 	void *data;
     50 };
     51 
     52 struct usbfs_setinterface {
     53 	/* keep in sync with usbdevice_fs.h:usbdevfs_setinterface */
     54 	unsigned int interface;
     55 	unsigned int altsetting;
     56 };
     57 
     58 #define USBFS_MAXDRIVERNAME 255
     59 
     60 struct usbfs_getdriver {
     61 	unsigned int interface;
     62 	char driver[USBFS_MAXDRIVERNAME + 1];
     63 };
     64 
     65 #define USBFS_URB_SHORT_NOT_OK		0x01
     66 #define USBFS_URB_ISO_ASAP			0x02
     67 #define USBFS_URB_BULK_CONTINUATION	0x04
     68 #define USBFS_URB_QUEUE_BULK		0x10
     69 #define USBFS_URB_ZERO_PACKET		0x40
     70 
     71 enum usbfs_urb_type {
     72 	USBFS_URB_TYPE_ISO = 0,
     73 	USBFS_URB_TYPE_INTERRUPT = 1,
     74 	USBFS_URB_TYPE_CONTROL = 2,
     75 	USBFS_URB_TYPE_BULK = 3,
     76 };
     77 
     78 struct usbfs_iso_packet_desc {
     79 	unsigned int length;
     80 	unsigned int actual_length;
     81 	unsigned int status;
     82 };
     83 
     84 #define MAX_ISO_BUFFER_LENGTH		49152 * 128
     85 #define MAX_BULK_BUFFER_LENGTH		16384
     86 #define MAX_CTRL_BUFFER_LENGTH		4096
     87 
     88 struct usbfs_urb {
     89 	unsigned char type;
     90 	unsigned char endpoint;
     91 	int status;
     92 	unsigned int flags;
     93 	void *buffer;
     94 	int buffer_length;
     95 	int actual_length;
     96 	int start_frame;
     97 	union {
     98 		int number_of_packets;	/* Only used for isoc urbs */
     99 		unsigned int stream_id;	/* Only used with bulk streams */
    100 	};
    101 	int error_count;
    102 	unsigned int signr;
    103 	void *usercontext;
    104 	struct usbfs_iso_packet_desc iso_frame_desc[0];
    105 };
    106 
    107 struct usbfs_connectinfo {
    108 	unsigned int devnum;
    109 	unsigned char slow;
    110 };
    111 
    112 struct 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 
    119 struct usbfs_hub_portinfo {
    120 	unsigned char numports;
    121 	unsigned char port[127];	/* port to device num mapping */
    122 };
    123 
    124 #define USBFS_CAP_ZERO_PACKET		0x01
    125 #define USBFS_CAP_BULK_CONTINUATION	0x02
    126 #define USBFS_CAP_NO_PACKET_SIZE_LIM	0x04
    127 #define USBFS_CAP_BULK_SCATTER_GATHER	0x08
    128 #define USBFS_CAP_REAP_AFTER_DISCONNECT	0x10
    129 
    130 #define USBFS_DISCONNECT_CLAIM_IF_DRIVER	0x01
    131 #define USBFS_DISCONNECT_CLAIM_EXCEPT_DRIVER	0x02
    132 
    133 struct usbfs_disconnect_claim {
    134 	unsigned int interface;
    135 	unsigned int flags;
    136 	char driver[USBFS_MAXDRIVERNAME + 1];
    137 };
    138 
    139 struct usbfs_streams {
    140 	unsigned int num_streams; /* Not used by USBDEVFS_FREE_STREAMS */
    141 	unsigned int num_eps;
    142 	unsigned char eps[0];
    143 };
    144 
    145 #define IOCTL_USBFS_CONTROL	_IOWR('U', 0, struct usbfs_ctrltransfer)
    146 #define IOCTL_USBFS_BULK		_IOWR('U', 2, struct usbfs_bulktransfer)
    147 #define IOCTL_USBFS_RESETEP	_IOR('U', 3, unsigned int)
    148 #define IOCTL_USBFS_SETINTF	_IOR('U', 4, struct usbfs_setinterface)
    149 #define IOCTL_USBFS_SETCONFIG	_IOR('U', 5, unsigned int)
    150 #define IOCTL_USBFS_GETDRIVER	_IOW('U', 8, struct usbfs_getdriver)
    151 #define IOCTL_USBFS_SUBMITURB	_IOR('U', 10, struct usbfs_urb)
    152 #define IOCTL_USBFS_DISCARDURB	_IO('U', 11)
    153 #define IOCTL_USBFS_REAPURB	_IOW('U', 12, void *)
    154 #define IOCTL_USBFS_REAPURBNDELAY	_IOW('U', 13, void *)
    155 #define IOCTL_USBFS_CLAIMINTF	_IOR('U', 15, unsigned int)
    156 #define IOCTL_USBFS_RELEASEINTF	_IOR('U', 16, unsigned int)
    157 #define IOCTL_USBFS_CONNECTINFO	_IOW('U', 17, struct usbfs_connectinfo)
    158 #define IOCTL_USBFS_IOCTL         _IOWR('U', 18, struct usbfs_ioctl)
    159 #define IOCTL_USBFS_HUB_PORTINFO	_IOR('U', 19, struct usbfs_hub_portinfo)
    160 #define IOCTL_USBFS_RESET		_IO('U', 20)
    161 #define IOCTL_USBFS_CLEAR_HALT	_IOR('U', 21, unsigned int)
    162 #define IOCTL_USBFS_DISCONNECT	_IO('U', 22)
    163 #define IOCTL_USBFS_CONNECT	_IO('U', 23)
    164 #define IOCTL_USBFS_CLAIM_PORT	_IOR('U', 24, unsigned int)
    165 #define IOCTL_USBFS_RELEASE_PORT	_IOR('U', 25, unsigned int)
    166 #define IOCTL_USBFS_GET_CAPABILITIES	_IOR('U', 26, __u32)
    167 #define IOCTL_USBFS_DISCONNECT_CLAIM	_IOR('U', 27, struct usbfs_disconnect_claim)
    168 #define IOCTL_USBFS_ALLOC_STREAMS	_IOR('U', 28, struct usbfs_streams)
    169 #define IOCTL_USBFS_FREE_STREAMS	_IOR('U', 29, struct usbfs_streams)
    170 
    171 extern usbi_mutex_static_t linux_hotplug_lock;
    172 
    173 #if defined(HAVE_LIBUDEV)
    174 int linux_udev_start_event_monitor(void);
    175 int linux_udev_stop_event_monitor(void);
    176 int linux_udev_scan_devices(struct libusb_context *ctx);
    177 void linux_udev_hotplug_poll(void);
    178 #else
    179 int linux_netlink_start_event_monitor(void);
    180 int linux_netlink_stop_event_monitor(void);
    181 void linux_netlink_hotplug_poll(void);
    182 #endif
    183 
    184 void linux_hotplug_enumerate(uint8_t busnum, uint8_t devaddr, const char *sys_name);
    185 void linux_device_disconnected(uint8_t busnum, uint8_t devaddr);
    186 
    187 int linux_get_device_address (struct libusb_context *ctx, int detached,
    188 	uint8_t *busnum, uint8_t *devaddr, const char *dev_node,
    189 	const char *sys_name);
    190 int linux_enumerate_device(struct libusb_context *ctx,
    191 	uint8_t busnum, uint8_t devaddr, const char *sysfs_dir);
    192 
    193 #endif
    194