linux_usbfs.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #ifndef LIBUSB_USBFS_H
  21. #define LIBUSB_USBFS_H
  22. #include <linux/types.h>
  23. #define SYSFS_DEVICE_PATH "/sys/bus/usb/devices"
  24. struct usbfs_ctrltransfer {
  25. /* keep in sync with usbdevice_fs.h:usbdevfs_ctrltransfer */
  26. uint8_t bmRequestType;
  27. uint8_t bRequest;
  28. uint16_t wValue;
  29. uint16_t wIndex;
  30. uint16_t wLength;
  31. uint32_t timeout; /* in milliseconds */
  32. /* pointer to data */
  33. void *data;
  34. };
  35. struct usbfs_bulktransfer {
  36. /* keep in sync with usbdevice_fs.h:usbdevfs_bulktransfer */
  37. unsigned int ep;
  38. unsigned int len;
  39. unsigned int timeout; /* in milliseconds */
  40. /* pointer to data */
  41. void *data;
  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. #define USBFS_MAXDRIVERNAME 255
  49. struct usbfs_getdriver {
  50. unsigned int interface;
  51. char driver[USBFS_MAXDRIVERNAME + 1];
  52. };
  53. #define USBFS_URB_SHORT_NOT_OK 0x01
  54. #define USBFS_URB_ISO_ASAP 0x02
  55. #define USBFS_URB_BULK_CONTINUATION 0x04
  56. #define USBFS_URB_QUEUE_BULK 0x10
  57. #define USBFS_URB_ZERO_PACKET 0x40
  58. enum usbfs_urb_type {
  59. USBFS_URB_TYPE_ISO = 0,
  60. USBFS_URB_TYPE_INTERRUPT = 1,
  61. USBFS_URB_TYPE_CONTROL = 2,
  62. USBFS_URB_TYPE_BULK = 3,
  63. };
  64. struct usbfs_iso_packet_desc {
  65. unsigned int length;
  66. unsigned int actual_length;
  67. unsigned int status;
  68. };
  69. #define MAX_ISO_BUFFER_LENGTH 32768
  70. #define MAX_BULK_BUFFER_LENGTH 16384
  71. #define MAX_CTRL_BUFFER_LENGTH 4096
  72. struct usbfs_urb {
  73. unsigned char type;
  74. unsigned char endpoint;
  75. int status;
  76. unsigned int flags;
  77. void *buffer;
  78. int buffer_length;
  79. int actual_length;
  80. int start_frame;
  81. int number_of_packets;
  82. int error_count;
  83. unsigned int signr;
  84. void *usercontext;
  85. struct usbfs_iso_packet_desc iso_frame_desc[0];
  86. };
  87. struct usbfs_connectinfo {
  88. unsigned int devnum;
  89. unsigned char slow;
  90. };
  91. struct usbfs_ioctl {
  92. int ifno; /* interface 0..N ; negative numbers reserved */
  93. int ioctl_code; /* MUST encode size + direction of data so the
  94. * macros in <asm/ioctl.h> give correct values */
  95. void *data; /* param buffer (in, or out) */
  96. };
  97. struct usbfs_hub_portinfo {
  98. unsigned char numports;
  99. unsigned char port[127]; /* port to device num mapping */
  100. };
  101. #define USBFS_CAP_ZERO_PACKET 0x01
  102. #define USBFS_CAP_BULK_CONTINUATION 0x02
  103. #define USBFS_CAP_NO_PACKET_SIZE_LIM 0x04
  104. #define USBFS_CAP_BULK_SCATTER_GATHER 0x08
  105. #define IOCTL_USBFS_CONTROL _IOWR('U', 0, struct usbfs_ctrltransfer)
  106. #define IOCTL_USBFS_BULK _IOWR('U', 2, struct usbfs_bulktransfer)
  107. #define IOCTL_USBFS_RESETEP _IOR('U', 3, unsigned int)
  108. #define IOCTL_USBFS_SETINTF _IOR('U', 4, struct usbfs_setinterface)
  109. #define IOCTL_USBFS_SETCONFIG _IOR('U', 5, unsigned int)
  110. #define IOCTL_USBFS_GETDRIVER _IOW('U', 8, struct usbfs_getdriver)
  111. #define IOCTL_USBFS_SUBMITURB _IOR('U', 10, struct usbfs_urb)
  112. #define IOCTL_USBFS_DISCARDURB _IO('U', 11)
  113. #define IOCTL_USBFS_REAPURB _IOW('U', 12, void *)
  114. #define IOCTL_USBFS_REAPURBNDELAY _IOW('U', 13, void *)
  115. #define IOCTL_USBFS_CLAIMINTF _IOR('U', 15, unsigned int)
  116. #define IOCTL_USBFS_RELEASEINTF _IOR('U', 16, unsigned int)
  117. #define IOCTL_USBFS_CONNECTINFO _IOW('U', 17, struct usbfs_connectinfo)
  118. #define IOCTL_USBFS_IOCTL _IOWR('U', 18, struct usbfs_ioctl)
  119. #define IOCTL_USBFS_HUB_PORTINFO _IOR('U', 19, struct usbfs_hub_portinfo)
  120. #define IOCTL_USBFS_RESET _IO('U', 20)
  121. #define IOCTL_USBFS_CLEAR_HALT _IOR('U', 21, unsigned int)
  122. #define IOCTL_USBFS_DISCONNECT _IO('U', 22)
  123. #define IOCTL_USBFS_CONNECT _IO('U', 23)
  124. #define IOCTL_USBFS_CLAIM_PORT _IOR('U', 24, unsigned int)
  125. #define IOCTL_USBFS_RELEASE_PORT _IOR('U', 25, unsigned int)
  126. #define IOCTL_USBFS_GET_CAPABILITIES _IOR('U', 26, __u32)
  127. #if defined(HAVE_LIBUDEV)
  128. int linux_udev_start_event_monitor(void);
  129. int linux_udev_stop_event_monitor(void);
  130. int linux_udev_scan_devices(struct libusb_context *ctx);
  131. #else
  132. int linux_netlink_start_event_monitor(void);
  133. int linux_netlink_stop_event_monitor(void);
  134. #endif
  135. void linux_hotplug_enumerate(uint8_t busnum, uint8_t devaddr, const char *sys_name);
  136. void linux_hotplug_disconnected(uint8_t busnum, uint8_t devaddr, const char *sys_name);
  137. int linux_get_device_address (struct libusb_context *ctx, int detached,
  138. uint8_t *busnum, uint8_t *devaddr,
  139. const char *dev_node, const char *sys_name);
  140. int linux_enumerate_device(struct libusb_context *ctx,
  141. uint8_t busnum, uint8_t devaddr,
  142. const char *sysfs_dir);
  143. #endif