usb_standard_types.hpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /*
  2. * Public libusb header file
  3. * Copyright (C) 2007-2008 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 __USB_STANDARD_TYPES_H__
  21. #define __USB_STANDARD_TYPES_H__
  22. #include <stdint.h>
  23. #include <sys/time.h>
  24. #include <sys/types.h>
  25. #include <time.h>
  26. #include <limits.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* standard USB stuff */
  31. /** \ingroup desc
  32. * Device and/or Interface Class codes */
  33. enum libusb_class_code {
  34. /** In the context of a \ref libusb_device_descriptor "device descriptor",
  35. * this bDeviceClass value indicates that each interface specifies its
  36. * own class information and all interfaces operate independently.
  37. */
  38. LIBUSB_CLASS_PER_INTERFACE = 0,
  39. /** Audio class */
  40. LIBUSB_CLASS_AUDIO = 1,
  41. /** Communications class */
  42. LIBUSB_CLASS_COMM = 2,
  43. /** Human Interface Device class */
  44. LIBUSB_CLASS_HID = 3,
  45. /** Printer dclass */
  46. LIBUSB_CLASS_PRINTER = 7,
  47. /** Picture transfer protocol class */
  48. LIBUSB_CLASS_PTP = 6,
  49. /** Mass storage class */
  50. LIBUSB_CLASS_MASS_STORAGE = 8,
  51. /** Hub class */
  52. LIBUSB_CLASS_HUB = 9,
  53. /** Data class */
  54. LIBUSB_CLASS_DATA = 10,
  55. /** Class is vendor-specific */
  56. LIBUSB_CLASS_VENDOR_SPEC = 0xff,
  57. };
  58. /** \ingroup desc
  59. * Descriptor types as defined by the USB specification. */
  60. enum libusb_descriptor_type {
  61. /** Device descriptor. See libusb_device_descriptor. */
  62. LIBUSB_DT_DEVICE = 0x01,
  63. /** Configuration descriptor. See libusb_config_descriptor. */
  64. LIBUSB_DT_CONFIG = 0x02,
  65. /** String descriptor */
  66. LIBUSB_DT_STRING = 0x03,
  67. /** Interface descriptor. See libusb_interface_descriptor. */
  68. LIBUSB_DT_INTERFACE = 0x04,
  69. /** Endpoint descriptor. See libusb_endpoint_descriptor. */
  70. LIBUSB_DT_ENDPOINT = 0x05,
  71. /** HID descriptor */
  72. LIBUSB_DT_HID = 0x21,
  73. /** HID report descriptor */
  74. LIBUSB_DT_REPORT = 0x22,
  75. /** Physical descriptor */
  76. LIBUSB_DT_PHYSICAL = 0x23,
  77. /** Hub descriptor */
  78. LIBUSB_DT_HUB = 0x29,
  79. };
  80. /* Descriptor sizes per descriptor type */
  81. #define LIBUSB_DT_DEVICE_SIZE 18
  82. #define LIBUSB_DT_CONFIG_SIZE 9
  83. #define LIBUSB_DT_INTERFACE_SIZE 9
  84. #define LIBUSB_DT_ENDPOINT_SIZE 7
  85. #define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
  86. #define LIBUSB_DT_HUB_NONVAR_SIZE 7
  87. #define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
  88. #define LIBUSB_ENDPOINT_DIR_MASK 0x80
  89. /** \ingroup desc
  90. * Endpoint direction. Values for bit 7 of the
  91. * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
  92. */
  93. enum libusb_endpoint_direction {
  94. /** In: device-to-host */
  95. LIBUSB_ENDPOINT_IN = 0x80,
  96. /** Out: host-to-device */
  97. LIBUSB_ENDPOINT_OUT = 0x00,
  98. };
  99. #define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */
  100. /** \ingroup desc
  101. * Endpoint transfer type. Values for bits 0:1 of the
  102. * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
  103. */
  104. enum libusb_transfer_type {
  105. /** Control endpoint */
  106. LIBUSB_TRANSFER_TYPE_CONTROL = 0,
  107. /** Isochronous endpoint */
  108. LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
  109. /** Bulk endpoint */
  110. LIBUSB_TRANSFER_TYPE_BULK = 2,
  111. /** Interrupt endpoint */
  112. LIBUSB_TRANSFER_TYPE_INTERRUPT = 3,
  113. };
  114. /** \ingroup misc
  115. * Standard requests, as defined in table 9-3 of the USB2 specifications */
  116. enum libusb_standard_request {
  117. /** Request status of the specific recipient */
  118. LIBUSB_REQUEST_GET_STATUS = 0x00,
  119. /** Clear or disable a specific feature */
  120. LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
  121. /* 0x02 is reserved */
  122. /** Set or enable a specific feature */
  123. LIBUSB_REQUEST_SET_FEATURE = 0x03,
  124. /* 0x04 is reserved */
  125. /** Set device address for all future accesses */
  126. LIBUSB_REQUEST_SET_ADDRESS = 0x05,
  127. /** Get the specified descriptor */
  128. LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
  129. /** Used to update existing descriptors or add new descriptors */
  130. LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
  131. /** Get the current device configuration value */
  132. LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
  133. /** Set device configuration */
  134. LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
  135. /** Return the selected alternate setting for the specified interface */
  136. LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
  137. /** Select an alternate interface for the specified interface */
  138. LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
  139. /** Set then report an endpoint's synchronization frame */
  140. LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
  141. };
  142. /** \ingroup misc
  143. * Request type bits of the
  144. * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
  145. * transfers. */
  146. enum libusb_request_type {
  147. /** Standard */
  148. LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
  149. /** Class */
  150. LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
  151. /** Vendor */
  152. LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
  153. /** Reserved */
  154. LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5),
  155. };
  156. /** \ingroup misc
  157. * Recipient bits of the
  158. * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
  159. * transfers. Values 4 through 31 are reserved. */
  160. enum libusb_request_recipient {
  161. /** Device */
  162. LIBUSB_RECIPIENT_DEVICE = 0x00,
  163. /** Interface */
  164. LIBUSB_RECIPIENT_INTERFACE = 0x01,
  165. /** Endpoint */
  166. LIBUSB_RECIPIENT_ENDPOINT = 0x02,
  167. /** Other */
  168. LIBUSB_RECIPIENT_OTHER = 0x03,
  169. };
  170. #define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
  171. /** \ingroup desc
  172. * Synchronization type for isochronous endpoints. Values for bits 2:3 of the
  173. * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
  174. * libusb_endpoint_descriptor.
  175. */
  176. enum libusb_iso_sync_type {
  177. /** No synchronization */
  178. LIBUSB_ISO_SYNC_TYPE_NONE = 0,
  179. /** Asynchronous */
  180. LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
  181. /** Adaptive */
  182. LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
  183. /** Synchronous */
  184. LIBUSB_ISO_SYNC_TYPE_SYNC = 3,
  185. };
  186. #define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
  187. /** \ingroup desc
  188. * Usage type for isochronous endpoints. Values for bits 4:5 of the
  189. * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
  190. * libusb_endpoint_descriptor.
  191. */
  192. enum libusb_iso_usage_type {
  193. /** Data endpoint */
  194. LIBUSB_ISO_USAGE_TYPE_DATA = 0,
  195. /** Feedback endpoint */
  196. LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
  197. /** Implicit feedback Data endpoint */
  198. LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
  199. };
  200. /** \ingroup desc
  201. * A structure representing the standard USB device descriptor. This
  202. * descriptor is documented in section 9.6.1 of the USB 2.0 specification.
  203. * All multiple-byte fields are represented in host-endian format.
  204. */
  205. struct libusb_device_descriptor {
  206. /** Size of this descriptor (in bytes) */
  207. uint8_t bLength;
  208. /** Descriptor type. Will have value
  209. * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this
  210. * context. */
  211. uint8_t bDescriptorType;
  212. /** USB specification release number in binary-coded decimal. A value of
  213. * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
  214. uint16_t bcdUSB;
  215. /** USB-IF class code for the device. See \ref libusb_class_code. */
  216. uint8_t bDeviceClass;
  217. /** USB-IF subclass code for the device, qualified by the bDeviceClass
  218. * value */
  219. uint8_t bDeviceSubClass;
  220. /** USB-IF protocol code for the device, qualified by the bDeviceClass and
  221. * bDeviceSubClass values */
  222. uint8_t bDeviceProtocol;
  223. /** Maximum packet size for endpoint 0 */
  224. uint8_t bMaxPacketSize0;
  225. /** USB-IF vendor ID */
  226. uint16_t idVendor;
  227. /** USB-IF product ID */
  228. uint16_t idProduct;
  229. /** Device release number in binary-coded decimal */
  230. uint16_t bcdDevice;
  231. /** Index of string descriptor describing manufacturer */
  232. uint8_t iManufacturer;
  233. /** Index of string descriptor describing product */
  234. uint8_t iProduct;
  235. /** Index of string descriptor containing device serial number */
  236. uint8_t iSerialNumber;
  237. /** Number of possible configurations */
  238. uint8_t bNumConfigurations;
  239. };
  240. /** \ingroup desc
  241. * A structure representing the standard USB endpoint descriptor. This
  242. * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
  243. * All multiple-byte fields are represented in host-endian format.
  244. */
  245. struct libusb_endpoint_descriptor {
  246. /** Size of this descriptor (in bytes) */
  247. uint8_t bLength;
  248. /** Descriptor type. Will have value
  249. * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in
  250. * this context. */
  251. uint8_t bDescriptorType;
  252. /** The address of the endpoint described by this descriptor. Bits 0:3 are
  253. * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,
  254. * see \ref libusb_endpoint_direction.
  255. */
  256. uint8_t bEndpointAddress;
  257. /** Attributes which apply to the endpoint when it is configured using
  258. * the bConfigurationValue. Bits 0:1 determine the transfer type and
  259. * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for
  260. * isochronous endpoints and correspond to \ref libusb_iso_sync_type.
  261. * Bits 4:5 are also only used for isochronous endpoints and correspond to
  262. * \ref libusb_iso_usage_type. Bits 6:7 are reserved.
  263. */
  264. uint8_t bmAttributes;
  265. /** Maximum packet size this endpoint is capable of sending/receiving. */
  266. uint16_t wMaxPacketSize;
  267. /** Interval for polling endpoint for data transfers. */
  268. uint8_t bInterval;
  269. /** For audio devices only: the rate at which synchronization feedback
  270. * is provided. */
  271. uint8_t bRefresh;
  272. /** For audio devices only: the address if the synch endpoint */
  273. uint8_t bSynchAddress;
  274. /** Extra descriptors. If libusb encounters unknown endpoint descriptors,
  275. * it will store them here, should you wish to parse them. */
  276. const unsigned char *extra;
  277. /** Length of the extra descriptors, in bytes. */
  278. int extra_length;
  279. };
  280. /** \ingroup desc
  281. * A structure representing the standard USB interface descriptor. This
  282. * descriptor is documented in section 9.6.5 of the USB 2.0 specification.
  283. * All multiple-byte fields are represented in host-endian format.
  284. */
  285. struct libusb_interface_descriptor {
  286. /** Size of this descriptor (in bytes) */
  287. uint8_t bLength;
  288. /** Descriptor type. Will have value
  289. * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE
  290. * in this context. */
  291. uint8_t bDescriptorType;
  292. /** Number of this interface */
  293. uint8_t bInterfaceNumber;
  294. /** Value used to select this alternate setting for this interface */
  295. uint8_t bAlternateSetting;
  296. /** Number of endpoints used by this interface (excluding the control
  297. * endpoint). */
  298. uint8_t bNumEndpoints;
  299. /** USB-IF class code for this interface. See \ref libusb_class_code. */
  300. uint8_t bInterfaceClass;
  301. /** USB-IF subclass code for this interface, qualified by the
  302. * bInterfaceClass value */
  303. uint8_t bInterfaceSubClass;
  304. /** USB-IF protocol code for this interface, qualified by the
  305. * bInterfaceClass and bInterfaceSubClass values */
  306. uint8_t bInterfaceProtocol;
  307. /** Index of string descriptor describing this interface */
  308. uint8_t iInterface;
  309. /** Array of endpoint descriptors. This length of this array is determined
  310. * by the bNumEndpoints field. */
  311. const struct libusb_endpoint_descriptor *endpoint;
  312. /** Extra descriptors. If libusb encounters unknown interface descriptors,
  313. * it will store them here, should you wish to parse them. */
  314. const unsigned char *extra;
  315. /** Length of the extra descriptors, in bytes. */
  316. int extra_length;
  317. };
  318. /** \ingroup desc
  319. * A structure representing the standard USB configuration descriptor. This
  320. * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
  321. * All multiple-byte fields are represented in host-endian format.
  322. */
  323. struct libusb_config_descriptor {
  324. /** Size of this descriptor (in bytes) */
  325. uint8_t bLength;
  326. /** Descriptor type. Will have value
  327. * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG
  328. * in this context. */
  329. uint8_t bDescriptorType;
  330. /** Total length of data returned for this configuration */
  331. uint16_t wTotalLength;
  332. /** Number of interfaces supported by this configuration */
  333. uint8_t bNumInterfaces;
  334. /** Identifier value for this configuration */
  335. uint8_t bConfigurationValue;
  336. /** Index of string descriptor describing this configuration */
  337. uint8_t iConfiguration;
  338. /** Configuration characteristics */
  339. uint8_t bmAttributes;
  340. /** Maximum power consumption of the USB device from this bus in this
  341. * configuration when the device is fully opreation. Expressed in units
  342. * of 2 mA. */
  343. uint8_t MaxPower;
  344. /** Array of interfaces supported by this configuration. The length of
  345. * this array is determined by the bNumInterfaces field. */
  346. const struct libusb_interface *interface;
  347. /** Extra descriptors. If libusb encounters unknown configuration
  348. * descriptors, it will store them here, should you wish to parse them. */
  349. const unsigned char *extra;
  350. /** Length of the extra descriptors, in bytes. */
  351. int extra_length;
  352. };
  353. /** \ingroup asyncio
  354. * Setup packet for control transfers. */
  355. struct libusb_control_setup {
  356. /** Request type. Bits 0:4 determine recipient, see
  357. * \ref libusb_request_recipient. Bits 5:6 determine type, see
  358. * \ref libusb_request_type. Bit 7 determines data transfer direction, see
  359. * \ref libusb_endpoint_direction.
  360. */
  361. uint8_t bmRequestType;
  362. /** Request. If the type bits of bmRequestType are equal to
  363. * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD
  364. * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to
  365. * \ref libusb_standard_request. For other cases, use of this field is
  366. * application-specific. */
  367. uint8_t bRequest;
  368. /** Value. Varies according to request */
  369. uint16_t wValue;
  370. /** Index. Varies according to request, typically used to pass an index
  371. * or offset */
  372. uint16_t wIndex;
  373. /** Number of bytes to transfer */
  374. uint16_t wLength;
  375. };
  376. #ifdef __cplusplus
  377. }
  378. #endif
  379. #endif