linux_usbfs.h 6.2 KB

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