| 1 |
/* |
| 2 |
* usbfs header structures |
| 3 |
* Copyright © 2007 Daniel Drake <[email protected]> |
| 4 |
* Copyright © 2001 Johannes Erdfelt <[email protected]> |
| 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/magic.h> |
| 25 |
#include <linux/types.h> |
| 26 |
|
| 27 |
#define SYSFS_MOUNT_PATH "/sys" |
| 28 |
#define SYSFS_DEVICE_PATH SYSFS_MOUNT_PATH "/bus/usb/devices" |
| 29 |
|
| 30 |
struct usbfs_ctrltransfer { |
| 31 |
/* keep in sync with usbdevice_fs.h:usbdevfs_ctrltransfer */ |
| 32 |
__u8 bmRequestType; |
| 33 |
__u8 bRequest; |
| 34 |
__u16 wValue; |
| 35 |
__u16 wIndex; |
| 36 |
__u16 wLength; |
| 37 |
__u32 timeout; /* in milliseconds */ |
| 38 |
|
| 39 |
/* pointer to data */ |
| 40 |
void *data; |
| 41 |
}; |
| 42 |
|
| 43 |
struct usbfs_setinterface { |
| 44 |
/* keep in sync with usbdevice_fs.h:usbdevfs_setinterface */ |
| 45 |
unsigned int interface; |
| 46 |
unsigned int altsetting; |
| 47 |
}; |
| 48 |
|
| 49 |
#define USBFS_MAXDRIVERNAME 255 |
| 50 |
|
| 51 |
struct usbfs_getdriver { |
| 52 |
unsigned int interface; |
| 53 |
char driver[USBFS_MAXDRIVERNAME + 1]; |
| 54 |
}; |
| 55 |
|
| 56 |
#define USBFS_URB_SHORT_NOT_OK 0x01 |
| 57 |
#define USBFS_URB_ISO_ASAP 0x02 |
| 58 |
#define USBFS_URB_BULK_CONTINUATION 0x04 |
| 59 |
#define USBFS_URB_QUEUE_BULK 0x10 |
| 60 |
#define USBFS_URB_ZERO_PACKET 0x40 |
| 61 |
|
| 62 |
#define USBFS_URB_TYPE_ISO 0 |
| 63 |
#define USBFS_URB_TYPE_INTERRUPT 1 |
| 64 |
#define USBFS_URB_TYPE_CONTROL 2 |
| 65 |
#define USBFS_URB_TYPE_BULK 3 |
| 66 |
|
| 67 |
struct usbfs_iso_packet_desc { |
| 68 |
unsigned int length; |
| 69 |
unsigned int actual_length; |
| 70 |
unsigned int status; |
| 71 |
}; |
| 72 |
|
| 73 |
#define MAX_BULK_BUFFER_LENGTH 16384 |
| 74 |
#define MAX_CTRL_BUFFER_LENGTH 4096 |
| 75 |
|
| 76 |
#define MAX_ISO_PACKETS_PER_URB 128 |
| 77 |
|
| 78 |
struct usbfs_urb { |
| 79 |
unsigned char type; |
| 80 |
unsigned char endpoint; |
| 81 |
int status; |
| 82 |
unsigned int flags; |
| 83 |
void *buffer; |
| 84 |
int buffer_length; |
| 85 |
int actual_length; |
| 86 |
int start_frame; |
| 87 |
union { |
| 88 |
int number_of_packets; /* Only used for isoc urbs */ |
| 89 |
unsigned int stream_id; /* Only used with bulk streams */ |
| 90 |
}; |
| 91 |
int error_count; |
| 92 |
unsigned int signr; |
| 93 |
void *usercontext; |
| 94 |
struct usbfs_iso_packet_desc iso_frame_desc[0]; |
| 95 |
}; |
| 96 |
|
| 97 |
struct usbfs_connectinfo { |
| 98 |
unsigned int devnum; |
| 99 |
unsigned char slow; |
| 100 |
}; |
| 101 |
|
| 102 |
struct usbfs_ioctl { |
| 103 |
int ifno; /* interface 0..N ; negative numbers reserved */ |
| 104 |
int ioctl_code; /* MUST encode size + direction of data so the |
| 105 |
* macros in <asm/ioctl.h> give correct values */ |
| 106 |
void *data; /* param buffer (in, or out) */ |
| 107 |
}; |
| 108 |
|
| 109 |
#define USBFS_CAP_ZERO_PACKET 0x01 |
| 110 |
#define USBFS_CAP_BULK_CONTINUATION 0x02 |
| 111 |
#define USBFS_CAP_NO_PACKET_SIZE_LIM 0x04 |
| 112 |
#define USBFS_CAP_BULK_SCATTER_GATHER 0x08 |
| 113 |
#define USBFS_CAP_REAP_AFTER_DISCONNECT 0x10 |
| 114 |
|
| 115 |
#define USBFS_DISCONNECT_CLAIM_IF_DRIVER 0x01 |
| 116 |
#define USBFS_DISCONNECT_CLAIM_EXCEPT_DRIVER 0x02 |
| 117 |
|
| 118 |
struct usbfs_disconnect_claim { |
| 119 |
unsigned int interface; |
| 120 |
unsigned int flags; |
| 121 |
char driver[USBFS_MAXDRIVERNAME + 1]; |
| 122 |
}; |
| 123 |
|
| 124 |
struct usbfs_streams { |
| 125 |
unsigned int num_streams; /* Not used by USBDEVFS_FREE_STREAMS */ |
| 126 |
unsigned int num_eps; |
| 127 |
unsigned char eps[0]; |
| 128 |
}; |
| 129 |
|
| 130 |
#define USBFS_SPEED_UNKNOWN 0 |
| 131 |
#define USBFS_SPEED_LOW 1 |
| 132 |
#define USBFS_SPEED_FULL 2 |
| 133 |
#define USBFS_SPEED_HIGH 3 |
| 134 |
#define USBFS_SPEED_WIRELESS 4 |
| 135 |
#define USBFS_SPEED_SUPER 5 |
| 136 |
#define USBFS_SPEED_SUPER_PLUS 6 |
| 137 |
|
| 138 |
#define IOCTL_USBFS_CONTROL _IOWR('U', 0, struct usbfs_ctrltransfer) |
| 139 |
#define IOCTL_USBFS_SETINTERFACE _IOR('U', 4, struct usbfs_setinterface) |
| 140 |
#define IOCTL_USBFS_SETCONFIGURATION _IOR('U', 5, unsigned int) |
| 141 |
#define IOCTL_USBFS_GETDRIVER _IOW('U', 8, struct usbfs_getdriver) |
| 142 |
#define IOCTL_USBFS_SUBMITURB _IOR('U', 10, struct usbfs_urb) |
| 143 |
#define IOCTL_USBFS_DISCARDURB _IO('U', 11) |
| 144 |
#define IOCTL_USBFS_REAPURBNDELAY _IOW('U', 13, void *) |
| 145 |
#define IOCTL_USBFS_CLAIMINTERFACE _IOR('U', 15, unsigned int) |
| 146 |
#define IOCTL_USBFS_RELEASEINTERFACE _IOR('U', 16, unsigned int) |
| 147 |
#define IOCTL_USBFS_CONNECTINFO _IOW('U', 17, struct usbfs_connectinfo) |
| 148 |
#define IOCTL_USBFS_IOCTL _IOWR('U', 18, struct usbfs_ioctl) |
| 149 |
#define IOCTL_USBFS_RESET _IO('U', 20) |
| 150 |
#define IOCTL_USBFS_CLEAR_HALT _IOR('U', 21, unsigned int) |
| 151 |
#define IOCTL_USBFS_DISCONNECT _IO('U', 22) |
| 152 |
#define IOCTL_USBFS_CONNECT _IO('U', 23) |
| 153 |
#define IOCTL_USBFS_GET_CAPABILITIES _IOR('U', 26, __u32) |
| 154 |
#define IOCTL_USBFS_DISCONNECT_CLAIM _IOR('U', 27, struct usbfs_disconnect_claim) |
| 155 |
#define IOCTL_USBFS_ALLOC_STREAMS _IOR('U', 28, struct usbfs_streams) |
| 156 |
#define IOCTL_USBFS_FREE_STREAMS _IOR('U', 29, struct usbfs_streams) |
| 157 |
#define IOCTL_USBFS_DROP_PRIVILEGES _IOW('U', 30, __u32) |
| 158 |
#define IOCTL_USBFS_GET_SPEED _IO('U', 31) |
| 159 |
|
| 160 |
extern usbi_mutex_static_t linux_hotplug_lock; |
| 161 |
|
| 162 |
#ifdef HAVE_LIBUDEV |
| 163 |
int linux_udev_start_event_monitor(void); |
| 164 |
int linux_udev_stop_event_monitor(void); |
| 165 |
int linux_udev_scan_devices(struct libusb_context *ctx); |
| 166 |
void linux_udev_hotplug_poll(void); |
| 167 |
#else |
| 168 |
int linux_netlink_start_event_monitor(void); |
| 169 |
int linux_netlink_stop_event_monitor(void); |
| 170 |
void linux_netlink_hotplug_poll(void); |
| 171 |
#endif |
| 172 |
|
| 173 |
static inline int linux_start_event_monitor(void) |
| 174 |
{ |
| 175 |
#if defined(HAVE_LIBUDEV) |
| 176 |
return linux_udev_start_event_monitor(); |
| 177 |
/* |
| 178 |
* __ANDROID__: preprocessor macro defined automatically by GCC for all Android |
| 179 |
* targets (i.e. both Android native applications, and Android OS-level |
| 180 |
* services) |
| 181 |
* |
| 182 |
* ANDROID_OS: compilation flag that should be set for using libusb from programs |
| 183 |
* running on Android at OS level (e.g. Android platform services). |
| 184 |
* The programs using libusb built with the ANDROID_OS flag must have |
| 185 |
* permission to access netlink sockets. |
| 186 |
*/ |
| 187 |
#elif !defined(__ANDROID__) || defined(ANDROID_OS) |
| 188 |
return linux_netlink_start_event_monitor(); |
| 189 |
#else |
| 190 |
return LIBUSB_SUCCESS; |
| 191 |
#endif |
| 192 |
} |
| 193 |
|
| 194 |
static inline void linux_stop_event_monitor(void) |
| 195 |
{ |
| 196 |
#if defined(HAVE_LIBUDEV) |
| 197 |
linux_udev_stop_event_monitor(); |
| 198 |
#elif !defined(__ANDROID__) || defined(ANDROID_OS) |
| 199 |
linux_netlink_stop_event_monitor(); |
| 200 |
#endif |
| 201 |
} |
| 202 |
|
| 203 |
static inline void linux_hotplug_poll(void) |
| 204 |
{ |
| 205 |
#if defined(HAVE_LIBUDEV) |
| 206 |
linux_udev_hotplug_poll(); |
| 207 |
#elif !defined(__ANDROID__) || defined(ANDROID_OS) |
| 208 |
linux_netlink_hotplug_poll(); |
| 209 |
#endif |
| 210 |
} |
| 211 |
|
| 212 |
void linux_hotplug_enumerate(uint8_t busnum, uint8_t devaddr, const char *sys_name); |
| 213 |
void linux_device_disconnected(uint8_t busnum, uint8_t devaddr); |
| 214 |
|
| 215 |
int linux_get_device_address(struct libusb_context *ctx, int detached, |
| 216 |
uint8_t *busnum, uint8_t *devaddr, const char *dev_node, |
| 217 |
const char *sys_name, int fd); |
| 218 |
int linux_enumerate_device(struct libusb_context *ctx, |
| 219 |
uint8_t busnum, uint8_t devaddr, const char *sysfs_dir); |
| 220 |
|
| 221 |
#endif |