libusb.h 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779
  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. * Copyright (C) 2012-2013 Nathan Hjelm <hjelmn@cs.unm.edu>
  6. * Copyright (C) 2012 Peter Stuge <peter@stuge.se>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef LIBUSB_H
  23. #define LIBUSB_H
  24. #ifdef _MSC_VER
  25. /* on MS environments, the inline keyword is available in C++ only */
  26. #define inline __inline
  27. /* ssize_t is also not available (copy/paste from MinGW) */
  28. #ifndef _SSIZE_T_DEFINED
  29. #define _SSIZE_T_DEFINED
  30. #undef ssize_t
  31. #ifdef _WIN64
  32. typedef __int64 ssize_t;
  33. #else
  34. typedef int ssize_t;
  35. #endif /* _WIN64 */
  36. #endif /* _SSIZE_T_DEFINED */
  37. #endif /* _MSC_VER */
  38. /* stdint.h is also not usually available on MS */
  39. #if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
  40. typedef unsigned __int8 uint8_t;
  41. typedef unsigned __int16 uint16_t;
  42. typedef unsigned __int32 uint32_t;
  43. #else
  44. #include <stdint.h>
  45. #endif
  46. #include <sys/types.h>
  47. #include <time.h>
  48. #include <limits.h>
  49. #if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__)
  50. #include <sys/time.h>
  51. #endif
  52. /* 'interface' might be defined as a macro on Windows, so we need to
  53. * undefine it so as not to break the current libusb API, because
  54. * libusb_config_descriptor has an 'interface' member
  55. * As this can be problematic if you include windows.h after libusb.h
  56. * in your sources, we force windows.h to be included first. */
  57. #if defined(_WIN32) || defined(__CYGWIN__)
  58. #include <windows.h>
  59. #if defined(interface)
  60. #undef interface
  61. #endif
  62. #endif
  63. /** \def LIBUSB_CALL
  64. * \ingroup misc
  65. * libusb's Windows calling convention.
  66. *
  67. * Under Windows, the selection of available compilers and configurations
  68. * means that, unlike other platforms, there is not <em>one true calling
  69. * convention</em> (calling convention: the manner in which parameters are
  70. * passed to funcions in the generated assembly code).
  71. *
  72. * Matching the Windows API itself, libusb uses the WINAPI convention (which
  73. * translates to the <tt>stdcall</tt> convention) and guarantees that the
  74. * library is compiled in this way. The public header file also includes
  75. * appropriate annotations so that your own software will use the right
  76. * convention, even if another convention is being used by default within
  77. * your codebase.
  78. *
  79. * The one consideration that you must apply in your software is to mark
  80. * all functions which you use as libusb callbacks with this LIBUSB_CALL
  81. * annotation, so that they too get compiled for the correct calling
  82. * convention.
  83. *
  84. * On non-Windows operating systems, this macro is defined as nothing. This
  85. * means that you can apply it to your code without worrying about
  86. * cross-platform compatibility.
  87. */
  88. /* LIBUSB_CALL must be defined on both definition and declaration of libusb
  89. * functions. You'd think that declaration would be enough, but cygwin will
  90. * complain about conflicting types unless both are marked this way.
  91. * The placement of this macro is important too; it must appear after the
  92. * return type, before the function name. See internal documentation for
  93. * API_EXPORTED.
  94. */
  95. #if defined(_WIN32) || defined(__CYGWIN__)
  96. #define LIBUSB_CALL WINAPI
  97. #else
  98. #define LIBUSB_CALL
  99. #endif
  100. #ifdef __cplusplus
  101. extern "C" {
  102. #endif
  103. /** \def libusb_cpu_to_le16
  104. * \ingroup misc
  105. * Convert a 16-bit value from host-endian to little-endian format. On
  106. * little endian systems, this function does nothing. On big endian systems,
  107. * the bytes are swapped.
  108. * \param x the host-endian value to convert
  109. * \returns the value in little-endian byte order
  110. */
  111. static inline uint16_t libusb_cpu_to_le16(const uint16_t x)
  112. {
  113. union {
  114. uint8_t b8[2];
  115. uint16_t b16;
  116. } _tmp;
  117. _tmp.b8[1] = x >> 8;
  118. _tmp.b8[0] = x & 0xff;
  119. return _tmp.b16;
  120. }
  121. /** \def libusb_le16_to_cpu
  122. * \ingroup misc
  123. * Convert a 16-bit value from little-endian to host-endian format. On
  124. * little endian systems, this function does nothing. On big endian systems,
  125. * the bytes are swapped.
  126. * \param x the little-endian value to convert
  127. * \returns the value in host-endian byte order
  128. */
  129. #define libusb_le16_to_cpu libusb_cpu_to_le16
  130. /* standard USB stuff */
  131. /** \ingroup desc
  132. * Device and/or Interface Class codes */
  133. enum libusb_class_code {
  134. /** In the context of a \ref libusb_device_descriptor "device descriptor",
  135. * this bDeviceClass value indicates that each interface specifies its
  136. * own class information and all interfaces operate independently.
  137. */
  138. LIBUSB_CLASS_PER_INTERFACE = 0,
  139. /** Audio class */
  140. LIBUSB_CLASS_AUDIO = 1,
  141. /** Communications class */
  142. LIBUSB_CLASS_COMM = 2,
  143. /** Human Interface Device class */
  144. LIBUSB_CLASS_HID = 3,
  145. /** Physical */
  146. LIBUSB_CLASS_PHYSICAL = 5,
  147. /** Printer class */
  148. LIBUSB_CLASS_PRINTER = 7,
  149. /** Image class */
  150. LIBUSB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */
  151. LIBUSB_CLASS_IMAGE = 6,
  152. /** Mass storage class */
  153. LIBUSB_CLASS_MASS_STORAGE = 8,
  154. /** Hub class */
  155. LIBUSB_CLASS_HUB = 9,
  156. /** Data class */
  157. LIBUSB_CLASS_DATA = 10,
  158. /** Smart Card */
  159. LIBUSB_CLASS_SMART_CARD = 0x0b,
  160. /** Content Security */
  161. LIBUSB_CLASS_CONTENT_SECURITY = 0x0d,
  162. /** Video */
  163. LIBUSB_CLASS_VIDEO = 0x0e,
  164. /** Personal Healthcare */
  165. LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
  166. /** Diagnostic Device */
  167. LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
  168. /** Wireless class */
  169. LIBUSB_CLASS_WIRELESS = 0xe0,
  170. /** Application class */
  171. LIBUSB_CLASS_APPLICATION = 0xfe,
  172. /** Class is vendor-specific */
  173. LIBUSB_CLASS_VENDOR_SPEC = 0xff
  174. };
  175. /** \ingroup desc
  176. * Descriptor types as defined by the USB specification. */
  177. enum libusb_descriptor_type {
  178. /** Device descriptor. See libusb_device_descriptor. */
  179. LIBUSB_DT_DEVICE = 0x01,
  180. /** Configuration descriptor. See libusb_config_descriptor. */
  181. LIBUSB_DT_CONFIG = 0x02,
  182. /** String descriptor */
  183. LIBUSB_DT_STRING = 0x03,
  184. /** Interface descriptor. See libusb_interface_descriptor. */
  185. LIBUSB_DT_INTERFACE = 0x04,
  186. /** Endpoint descriptor. See libusb_endpoint_descriptor. */
  187. LIBUSB_DT_ENDPOINT = 0x05,
  188. /** HID descriptor */
  189. LIBUSB_DT_HID = 0x21,
  190. /** HID report descriptor */
  191. LIBUSB_DT_REPORT = 0x22,
  192. /** Physical descriptor */
  193. LIBUSB_DT_PHYSICAL = 0x23,
  194. /** Hub descriptor */
  195. LIBUSB_DT_HUB = 0x29,
  196. /** BOS descriptor */
  197. LIBUSB_DT_BOS = 0x0f,
  198. /** Device Capability descriptor */
  199. LIBUSB_DT_DEVICE_CAPABILITY = 0x10,
  200. /** SuperSpeed Endpoint Companion descriptor */
  201. LIBUSB_DT_SS_ENDPOINT_COMPANION = 0x30
  202. };
  203. /* Descriptor sizes per descriptor type */
  204. #define LIBUSB_DT_DEVICE_SIZE 18
  205. #define LIBUSB_DT_CONFIG_SIZE 9
  206. #define LIBUSB_DT_INTERFACE_SIZE 9
  207. #define LIBUSB_DT_ENDPOINT_SIZE 7
  208. #define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
  209. #define LIBUSB_DT_HUB_NONVAR_SIZE 7
  210. #define LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE 6
  211. #define LIBUSB_DT_BOS_SIZE 5
  212. #define LIBUSB_USB_2_0_EXTENSION_DEVICE_CAPABILITY_SIZE 7
  213. #define LIBUSB_SS_USB_DEVICE_CAPABILITY_SIZE 10
  214. #define LIBUSB_DT_BOS_MAX_SIZE ((LIBUSB_DT_BOS_SIZE) + \
  215. (LIBUSB_USB_2_0_EXTENSION_DEVICE_CAPABILITY_SIZE) + \
  216. (LIBUSB_SS_USB_DEVICE_CAPABILITY_SIZE))
  217. #define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
  218. #define LIBUSB_ENDPOINT_DIR_MASK 0x80
  219. /** \ingroup desc
  220. * Endpoint direction. Values for bit 7 of the
  221. * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
  222. */
  223. enum libusb_endpoint_direction {
  224. /** In: device-to-host */
  225. LIBUSB_ENDPOINT_IN = 0x80,
  226. /** Out: host-to-device */
  227. LIBUSB_ENDPOINT_OUT = 0x00
  228. };
  229. #define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */
  230. /** \ingroup desc
  231. * Endpoint transfer type. Values for bits 0:1 of the
  232. * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
  233. */
  234. enum libusb_transfer_type {
  235. /** Control endpoint */
  236. LIBUSB_TRANSFER_TYPE_CONTROL = 0,
  237. /** Isochronous endpoint */
  238. LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
  239. /** Bulk endpoint */
  240. LIBUSB_TRANSFER_TYPE_BULK = 2,
  241. /** Interrupt endpoint */
  242. LIBUSB_TRANSFER_TYPE_INTERRUPT = 3
  243. };
  244. /** \ingroup misc
  245. * Standard requests, as defined in table 9-3 of the USB2 specifications */
  246. enum libusb_standard_request {
  247. /** Request status of the specific recipient */
  248. LIBUSB_REQUEST_GET_STATUS = 0x00,
  249. /** Clear or disable a specific feature */
  250. LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
  251. /* 0x02 is reserved */
  252. /** Set or enable a specific feature */
  253. LIBUSB_REQUEST_SET_FEATURE = 0x03,
  254. /* 0x04 is reserved */
  255. /** Set device address for all future accesses */
  256. LIBUSB_REQUEST_SET_ADDRESS = 0x05,
  257. /** Get the specified descriptor */
  258. LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
  259. /** Used to update existing descriptors or add new descriptors */
  260. LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
  261. /** Get the current device configuration value */
  262. LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
  263. /** Set device configuration */
  264. LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
  265. /** Return the selected alternate setting for the specified interface */
  266. LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
  267. /** Select an alternate interface for the specified interface */
  268. LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
  269. /** Set then report an endpoint's synchronization frame */
  270. LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
  271. };
  272. /** \ingroup misc
  273. * Request type bits of the
  274. * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
  275. * transfers. */
  276. enum libusb_request_type {
  277. /** Standard */
  278. LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
  279. /** Class */
  280. LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
  281. /** Vendor */
  282. LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
  283. /** Reserved */
  284. LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)
  285. };
  286. /** \ingroup misc
  287. * Recipient bits of the
  288. * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
  289. * transfers. Values 4 through 31 are reserved. */
  290. enum libusb_request_recipient {
  291. /** Device */
  292. LIBUSB_RECIPIENT_DEVICE = 0x00,
  293. /** Interface */
  294. LIBUSB_RECIPIENT_INTERFACE = 0x01,
  295. /** Endpoint */
  296. LIBUSB_RECIPIENT_ENDPOINT = 0x02,
  297. /** Other */
  298. LIBUSB_RECIPIENT_OTHER = 0x03,
  299. };
  300. #define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
  301. /** \ingroup desc
  302. * Synchronization type for isochronous endpoints. Values for bits 2:3 of the
  303. * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
  304. * libusb_endpoint_descriptor.
  305. */
  306. enum libusb_iso_sync_type {
  307. /** No synchronization */
  308. LIBUSB_ISO_SYNC_TYPE_NONE = 0,
  309. /** Asynchronous */
  310. LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
  311. /** Adaptive */
  312. LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
  313. /** Synchronous */
  314. LIBUSB_ISO_SYNC_TYPE_SYNC = 3
  315. };
  316. #define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
  317. /** \ingroup desc
  318. * Usage type for isochronous endpoints. Values for bits 4:5 of the
  319. * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
  320. * libusb_endpoint_descriptor.
  321. */
  322. enum libusb_iso_usage_type {
  323. /** Data endpoint */
  324. LIBUSB_ISO_USAGE_TYPE_DATA = 0,
  325. /** Feedback endpoint */
  326. LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
  327. /** Implicit feedback Data endpoint */
  328. LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
  329. };
  330. /** \ingroup desc
  331. * A structure representing the standard USB device descriptor. This
  332. * descriptor is documented in section 9.6.1 of the USB 2.0 specification.
  333. * All multiple-byte fields are represented in host-endian format.
  334. */
  335. struct libusb_device_descriptor {
  336. /** Size of this descriptor (in bytes) */
  337. uint8_t bLength;
  338. /** Descriptor type. Will have value
  339. * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this
  340. * context. */
  341. uint8_t bDescriptorType;
  342. /** USB specification release number in binary-coded decimal. A value of
  343. * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
  344. uint16_t bcdUSB;
  345. /** USB-IF class code for the device. See \ref libusb_class_code. */
  346. uint8_t bDeviceClass;
  347. /** USB-IF subclass code for the device, qualified by the bDeviceClass
  348. * value */
  349. uint8_t bDeviceSubClass;
  350. /** USB-IF protocol code for the device, qualified by the bDeviceClass and
  351. * bDeviceSubClass values */
  352. uint8_t bDeviceProtocol;
  353. /** Maximum packet size for endpoint 0 */
  354. uint8_t bMaxPacketSize0;
  355. /** USB-IF vendor ID */
  356. uint16_t idVendor;
  357. /** USB-IF product ID */
  358. uint16_t idProduct;
  359. /** Device release number in binary-coded decimal */
  360. uint16_t bcdDevice;
  361. /** Index of string descriptor describing manufacturer */
  362. uint8_t iManufacturer;
  363. /** Index of string descriptor describing product */
  364. uint8_t iProduct;
  365. /** Index of string descriptor containing device serial number */
  366. uint8_t iSerialNumber;
  367. /** Number of possible configurations */
  368. uint8_t bNumConfigurations;
  369. };
  370. /** \ingroup desc
  371. * A structure representing the superspeed endpoint companion
  372. * descriptor. This descriptor is documented in section 9.6.7 of
  373. * the USB 3.0 specification. All ultiple-byte fields are represented in
  374. * host-endian format.
  375. */
  376. struct libusb_ss_endpoint_companion_descriptor {
  377. /** Size of this descriptor (in bytes) */
  378. uint8_t bLength;
  379. /** Descriptor type. Will have value
  380. * \ref libusb_descriptor_type::LIBUSB_DT_SS_ENDPOINT_COMPANION in
  381. * this context. */
  382. uint8_t bDescriptorType;
  383. /** The maximum number of packets the endpoint can send or
  384. * recieve as part of a burst. */
  385. uint8_t bMaxBurst;
  386. /** In bulk EP: bits 4:0 represents the maximum number of
  387. * streams the EP supports. In isochronous EP: bits 1:0
  388. * represents the Mult - a zero based value that determines
  389. * the maximum number of packets within a service interval */
  390. uint8_t bmAttributes;
  391. /** The total number of bytes this EP will transfer every
  392. * service interval. valid only for periodic EPs. */
  393. uint16_t wBytesPerInterval;
  394. };
  395. /** \ingroup desc
  396. * A structure representing the standard USB endpoint descriptor. This
  397. * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
  398. * All multiple-byte fields are represented in host-endian format.
  399. */
  400. struct libusb_endpoint_descriptor {
  401. /** Size of this descriptor (in bytes) */
  402. uint8_t bLength;
  403. /** Descriptor type. Will have value
  404. * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in
  405. * this context. */
  406. uint8_t bDescriptorType;
  407. /** The address of the endpoint described by this descriptor. Bits 0:3 are
  408. * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,
  409. * see \ref libusb_endpoint_direction.
  410. */
  411. uint8_t bEndpointAddress;
  412. /** Attributes which apply to the endpoint when it is configured using
  413. * the bConfigurationValue. Bits 0:1 determine the transfer type and
  414. * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for
  415. * isochronous endpoints and correspond to \ref libusb_iso_sync_type.
  416. * Bits 4:5 are also only used for isochronous endpoints and correspond to
  417. * \ref libusb_iso_usage_type. Bits 6:7 are reserved.
  418. */
  419. uint8_t bmAttributes;
  420. /** Maximum packet size this endpoint is capable of sending/receiving. */
  421. uint16_t wMaxPacketSize;
  422. /** Interval for polling endpoint for data transfers. */
  423. uint8_t bInterval;
  424. /** For audio devices only: the rate at which synchronization feedback
  425. * is provided. */
  426. uint8_t bRefresh;
  427. /** For audio devices only: the address if the synch endpoint */
  428. uint8_t bSynchAddress;
  429. /** Extra descriptors. If libusb encounters unknown endpoint descriptors,
  430. * it will store them here, should you wish to parse them. */
  431. const unsigned char *extra;
  432. /** Length of the extra descriptors, in bytes. */
  433. int extra_length;
  434. };
  435. /** \ingroup desc
  436. * A structure representing the standard USB interface descriptor. This
  437. * descriptor is documented in section 9.6.5 of the USB 2.0 specification.
  438. * All multiple-byte fields are represented in host-endian format.
  439. */
  440. struct libusb_interface_descriptor {
  441. /** Size of this descriptor (in bytes) */
  442. uint8_t bLength;
  443. /** Descriptor type. Will have value
  444. * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE
  445. * in this context. */
  446. uint8_t bDescriptorType;
  447. /** Number of this interface */
  448. uint8_t bInterfaceNumber;
  449. /** Value used to select this alternate setting for this interface */
  450. uint8_t bAlternateSetting;
  451. /** Number of endpoints used by this interface (excluding the control
  452. * endpoint). */
  453. uint8_t bNumEndpoints;
  454. /** USB-IF class code for this interface. See \ref libusb_class_code. */
  455. uint8_t bInterfaceClass;
  456. /** USB-IF subclass code for this interface, qualified by the
  457. * bInterfaceClass value */
  458. uint8_t bInterfaceSubClass;
  459. /** USB-IF protocol code for this interface, qualified by the
  460. * bInterfaceClass and bInterfaceSubClass values */
  461. uint8_t bInterfaceProtocol;
  462. /** Index of string descriptor describing this interface */
  463. uint8_t iInterface;
  464. /** Array of endpoint descriptors. This length of this array is determined
  465. * by the bNumEndpoints field. */
  466. const struct libusb_endpoint_descriptor *endpoint;
  467. /** Extra descriptors. If libusb encounters unknown interface descriptors,
  468. * it will store them here, should you wish to parse them. */
  469. const unsigned char *extra;
  470. /** Length of the extra descriptors, in bytes. */
  471. int extra_length;
  472. };
  473. /** \ingroup desc
  474. * A collection of alternate settings for a particular USB interface.
  475. */
  476. struct libusb_interface {
  477. /** Array of interface descriptors. The length of this array is determined
  478. * by the num_altsetting field. */
  479. const struct libusb_interface_descriptor *altsetting;
  480. /** The number of alternate settings that belong to this interface */
  481. int num_altsetting;
  482. };
  483. /** \ingroup desc
  484. * A structure representing the standard USB configuration descriptor. This
  485. * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
  486. * All multiple-byte fields are represented in host-endian format.
  487. */
  488. struct libusb_config_descriptor {
  489. /** Size of this descriptor (in bytes) */
  490. uint8_t bLength;
  491. /** Descriptor type. Will have value
  492. * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG
  493. * in this context. */
  494. uint8_t bDescriptorType;
  495. /** Total length of data returned for this configuration */
  496. uint16_t wTotalLength;
  497. /** Number of interfaces supported by this configuration */
  498. uint8_t bNumInterfaces;
  499. /** Identifier value for this configuration */
  500. uint8_t bConfigurationValue;
  501. /** Index of string descriptor describing this configuration */
  502. uint8_t iConfiguration;
  503. /** Configuration characteristics */
  504. uint8_t bmAttributes;
  505. /** Maximum power consumption of the USB device from this bus in this
  506. * configuration when the device is fully opreation. Expressed in units
  507. * of 2 mA. */
  508. uint8_t MaxPower;
  509. /** Array of interfaces supported by this configuration. The length of
  510. * this array is determined by the bNumInterfaces field. */
  511. const struct libusb_interface *interface;
  512. /** Extra descriptors. If libusb encounters unknown configuration
  513. * descriptors, it will store them here, should you wish to parse them. */
  514. const unsigned char *extra;
  515. /** Length of the extra descriptors, in bytes. */
  516. int extra_length;
  517. };
  518. /** \ingroup desc
  519. * A structure representing the BOS descriptor. This
  520. * descriptor is documented in section 9.6.2 of the USB 3.0
  521. * specification. All multiple-byte fields are represented in
  522. * host-endian format.
  523. */
  524. struct libusb_bos_descriptor {
  525. /** Size of this descriptor (in bytes) */
  526. uint8_t bLength;
  527. /** Descriptor type. Will have value
  528. * \ref libusb_descriptor_type::LIBUSB_DT_BOS LIBUSB_DT_BOS
  529. * in this context. */
  530. uint8_t bDescriptorType;
  531. /** Length of this descriptor and all of its sub descriptors */
  532. uint16_t wTotalLength;
  533. /** The number of separate device capability descriptors in
  534. * the BOS */
  535. uint8_t bNumDeviceCaps;
  536. /** USB 2.0 extension capability descriptor */
  537. struct libusb_usb_2_0_device_capability_descriptor *usb_2_0_ext_cap;
  538. /** SuperSpeed capabilty descriptor */
  539. struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap;
  540. };
  541. /** \ingroup desc
  542. * A structure representing the device capability descriptor for
  543. * USB 2.0. This descriptor is documented in section 9.6.2.1 of
  544. * the USB 3.0 specification. All mutiple-byte fields are represented
  545. * in host-endian format.
  546. */
  547. struct libusb_usb_2_0_device_capability_descriptor {
  548. /** Size of this descriptor (in bytes) */
  549. uint8_t bLength;
  550. /** Descriptor type. Will have value
  551. * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
  552. * LIBUSB_DT_DEVICE_CAPABILITY in this context. */
  553. uint8_t bDescriptorType;
  554. /** Capability type. Will have value
  555. * \ref libusb_capability_type::LIBUSB_USB_CAP_TYPE_EXT
  556. * LIBUSB_USB_CAP_TYPE_EXT in this context. */
  557. uint8_t bDevCapabilityType;
  558. /** Bitmap encoding of supported device level features.
  559. * A value of one in a bit location indicates a feature is
  560. * supported; a value of zero indicates it is not supported.
  561. * See \ref libusb_capability_attributes. */
  562. uint32_t bmAttributes;
  563. };
  564. /** \ingroup desc
  565. * A structure representing the device capability descriptor for
  566. * USB 3.0. This descriptor is documented in section 9.6.2.2 of
  567. * the USB 3.0 specification. All mutiple-byte fields are represented
  568. * in host-endian format.
  569. */
  570. struct libusb_ss_usb_device_capability_descriptor {
  571. /** Size of this descriptor (in bytes) */
  572. uint8_t bLength;
  573. /** Descriptor type. Will have value
  574. * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
  575. * LIBUSB_DT_DEVICE_CAPABILITY in this context. */
  576. uint8_t bDescriptorType;
  577. /** Capability type. Will have value
  578. * \ref libusb_capability_type::LIBUSB_SS_USB_CAP_TYPE
  579. * LIBUSB_SS_USB_CAP_TYPE in this context. */
  580. uint8_t bDevCapabilityType;
  581. /** Bitmap encoding of supported device level features.
  582. * A value of one in a bit location indicates a feature is
  583. * supported; a value of zero indicates it is not supported.
  584. * See \ref libusb_capability_attributes. */
  585. uint8_t bmAttributes;
  586. /** Bitmap encoding of the speed supported by this device when
  587. * operating in SuperSpeed mode. See \ref libusb_supported_speed. */
  588. uint16_t wSpeedSupported;
  589. /** The lowest speed at which all the functionality supported
  590. * by the device is available to the user. For example if the
  591. * device supports all its functionality when connected at
  592. * full speed and above then it sets this value to 1. */
  593. uint8_t bFunctionalitySupport;
  594. /** U1 Device Exit Latency. */
  595. uint8_t bU1DevExitLat;
  596. /** U2 Device Exit Latency. */
  597. uint16_t bU2DevExitLat;
  598. };
  599. /** \ingroup asyncio
  600. * Setup packet for control transfers. */
  601. struct libusb_control_setup {
  602. /** Request type. Bits 0:4 determine recipient, see
  603. * \ref libusb_request_recipient. Bits 5:6 determine type, see
  604. * \ref libusb_request_type. Bit 7 determines data transfer direction, see
  605. * \ref libusb_endpoint_direction.
  606. */
  607. uint8_t bmRequestType;
  608. /** Request. If the type bits of bmRequestType are equal to
  609. * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD
  610. * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to
  611. * \ref libusb_standard_request. For other cases, use of this field is
  612. * application-specific. */
  613. uint8_t bRequest;
  614. /** Value. Varies according to request */
  615. uint16_t wValue;
  616. /** Index. Varies according to request, typically used to pass an index
  617. * or offset */
  618. uint16_t wIndex;
  619. /** Number of bytes to transfer */
  620. uint16_t wLength;
  621. };
  622. #define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
  623. /* libusb */
  624. struct libusb_context;
  625. struct libusb_device;
  626. struct libusb_device_handle;
  627. struct libusb_hotplug_callback;
  628. /** \ingroup lib
  629. * Structure representing the libusb version.
  630. */
  631. struct libusb_version {
  632. /** Library major version. */
  633. const uint16_t major;
  634. /** Library minor version. */
  635. const uint16_t minor;
  636. /** Library micro version. */
  637. const uint16_t micro;
  638. /** Library nano version. This field is only nonzero on Windows. */
  639. const uint16_t nano;
  640. /** Library release candidate suffix string, e.g. "-rc4". */
  641. const char *rc;
  642. /** Output of `git describe --tags` at library build time. */
  643. const char *describe;
  644. };
  645. /** \ingroup lib
  646. * Structure representing a libusb session. The concept of individual libusb
  647. * sessions allows for your program to use two libraries (or dynamically
  648. * load two modules) which both independently use libusb. This will prevent
  649. * interference between the individual libusb users - for example
  650. * libusb_set_debug() will not affect the other user of the library, and
  651. * libusb_exit() will not destroy resources that the other user is still
  652. * using.
  653. *
  654. * Sessions are created by libusb_init() and destroyed through libusb_exit().
  655. * If your application is guaranteed to only ever include a single libusb
  656. * user (i.e. you), you do not have to worry about contexts: pass NULL in
  657. * every function call where a context is required. The default context
  658. * will be used.
  659. *
  660. * For more information, see \ref contexts.
  661. */
  662. typedef struct libusb_context libusb_context;
  663. /** \ingroup dev
  664. * Structure representing a USB device detected on the system. This is an
  665. * opaque type for which you are only ever provided with a pointer, usually
  666. * originating from libusb_get_device_list().
  667. *
  668. * Certain operations can be performed on a device, but in order to do any
  669. * I/O you will have to first obtain a device handle using libusb_open().
  670. *
  671. * Devices are reference counted with libusb_ref_device() and
  672. * libusb_unref_device(), and are freed when the reference count reaches 0.
  673. * New devices presented by libusb_get_device_list() have a reference count of
  674. * 1, and libusb_free_device_list() can optionally decrease the reference count
  675. * on all devices in the list. libusb_open() adds another reference which is
  676. * later destroyed by libusb_close().
  677. */
  678. typedef struct libusb_device libusb_device;
  679. /** \ingroup dev
  680. * Structure representing a handle on a USB device. This is an opaque type for
  681. * which you are only ever provided with a pointer, usually originating from
  682. * libusb_open().
  683. *
  684. * A device handle is used to perform I/O and other operations. When finished
  685. * with a device handle, you should call libusb_close().
  686. */
  687. typedef struct libusb_device_handle libusb_device_handle;
  688. /** \ingroup dev
  689. * Speed codes. Indicates the speed at which the device is operating.
  690. */
  691. enum libusb_speed {
  692. /** The OS doesn't report or know the device speed. */
  693. LIBUSB_SPEED_UNKNOWN = 0,
  694. /** The device is operating at low speed (1.5MBit/s). */
  695. LIBUSB_SPEED_LOW = 1,
  696. /** The device is operating at full speed (12MBit/s). */
  697. LIBUSB_SPEED_FULL = 2,
  698. /** The device is operating at high speed (480MBit/s). */
  699. LIBUSB_SPEED_HIGH = 3,
  700. /** The device is operating at super speed (5000MBit/s). */
  701. LIBUSB_SPEED_SUPER = 4,
  702. };
  703. /** \ingroup dev
  704. * Supported speeds (wSpeedSupported) bitfield. Indicates what
  705. * speeds the device supports.
  706. */
  707. enum libusb_supported_speed {
  708. /** Low speed operation supported (1.5MBit/s). */
  709. LIBUSB_LOW_SPEED_OPERATION = 1,
  710. /** Full speed operation supported (12MBit/s). */
  711. LIBUSB_FULL_SPEED_OPERATION = 2,
  712. /** High speed operation supported (480MBit/s). */
  713. LIBUSB_HIGH_SPEED_OPERATION = 4,
  714. /** Superspeed operation supported (5000MBit/s). */
  715. LIBUSB_5GBPS_OPERATION = 8,
  716. };
  717. /** \ingroup dev
  718. * Capability attributes
  719. */
  720. enum libusb_capability_attributes {
  721. /** Supports Link Power Management (LPM) */
  722. LIBUSB_LPM_SUPPORT = 2,
  723. };
  724. /** \ingroup dev
  725. * USB capability types
  726. */
  727. enum libusb_capability_type {
  728. /** USB 2.0 extension capability type */
  729. LIBUSB_USB_CAP_TYPE_EXT = 2,
  730. /** SuperSpeed capability type */
  731. LIBUSB_SS_USB_CAP_TYPE = 3,
  732. };
  733. /** \ingroup misc
  734. * Error codes. Most libusb functions return 0 on success or one of these
  735. * codes on failure.
  736. * You can call \ref libusb_error_name() to retrieve a string representation
  737. * of an error code or \ret libusb_strerror() to get an english description
  738. * of an error code.
  739. */
  740. enum libusb_error {
  741. /** Success (no error) */
  742. LIBUSB_SUCCESS = 0,
  743. /** Input/output error */
  744. LIBUSB_ERROR_IO = -1,
  745. /** Invalid parameter */
  746. LIBUSB_ERROR_INVALID_PARAM = -2,
  747. /** Access denied (insufficient permissions) */
  748. LIBUSB_ERROR_ACCESS = -3,
  749. /** No such device (it may have been disconnected) */
  750. LIBUSB_ERROR_NO_DEVICE = -4,
  751. /** Entity not found */
  752. LIBUSB_ERROR_NOT_FOUND = -5,
  753. /** Resource busy */
  754. LIBUSB_ERROR_BUSY = -6,
  755. /** Operation timed out */
  756. LIBUSB_ERROR_TIMEOUT = -7,
  757. /** Overflow */
  758. LIBUSB_ERROR_OVERFLOW = -8,
  759. /** Pipe error */
  760. LIBUSB_ERROR_PIPE = -9,
  761. /** System call interrupted (perhaps due to signal) */
  762. LIBUSB_ERROR_INTERRUPTED = -10,
  763. /** Insufficient memory */
  764. LIBUSB_ERROR_NO_MEM = -11,
  765. /** Operation not supported or unimplemented on this platform */
  766. LIBUSB_ERROR_NOT_SUPPORTED = -12,
  767. /* NB! Remember to update libusb_error_name() and
  768. libusb_strerror() when adding new error codes here. */
  769. /** Other error */
  770. LIBUSB_ERROR_OTHER = -99,
  771. };
  772. /** \ingroup asyncio
  773. * Transfer status codes */
  774. enum libusb_transfer_status {
  775. /** Transfer completed without error. Note that this does not indicate
  776. * that the entire amount of requested data was transferred. */
  777. LIBUSB_TRANSFER_COMPLETED,
  778. /** Transfer failed */
  779. LIBUSB_TRANSFER_ERROR,
  780. /** Transfer timed out */
  781. LIBUSB_TRANSFER_TIMED_OUT,
  782. /** Transfer was cancelled */
  783. LIBUSB_TRANSFER_CANCELLED,
  784. /** For bulk/interrupt endpoints: halt condition detected (endpoint
  785. * stalled). For control endpoints: control request not supported. */
  786. LIBUSB_TRANSFER_STALL,
  787. /** Device was disconnected */
  788. LIBUSB_TRANSFER_NO_DEVICE,
  789. /** Device sent more data than requested */
  790. LIBUSB_TRANSFER_OVERFLOW,
  791. };
  792. /** \ingroup asyncio
  793. * libusb_transfer.flags values */
  794. enum libusb_transfer_flags {
  795. /** Report short frames as errors */
  796. LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
  797. /** Automatically free() transfer buffer during libusb_free_transfer() */
  798. LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
  799. /** Automatically call libusb_free_transfer() after callback returns.
  800. * If this flag is set, it is illegal to call libusb_free_transfer()
  801. * from your transfer callback, as this will result in a double-free
  802. * when this flag is acted upon. */
  803. LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,
  804. /** Terminate transfers that are a multiple of the endpoint's
  805. * wMaxPacketSize with an extra zero length packet. This is useful
  806. * when a device protocol mandates that each logical request is
  807. * terminated by an incomplete packet (i.e. the logical requests are
  808. * not separated by other means).
  809. *
  810. * This flag only affects host-to-device transfers to bulk and interrupt
  811. * endpoints. In other situations, it is ignored.
  812. *
  813. * This flag only affects transfers with a length that is a multiple of
  814. * the endpoint's wMaxPacketSize. On transfers of other lengths, this
  815. * flag has no effect. Therefore, if you are working with a device that
  816. * needs a ZLP whenever the end of the logical request falls on a packet
  817. * boundary, then it is sensible to set this flag on <em>every</em>
  818. * transfer (you do not have to worry about only setting it on transfers
  819. * that end on the boundary).
  820. *
  821. * This flag is currently only supported on Linux.
  822. * On other systems, libusb_submit_transfer() will return
  823. * LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag is set.
  824. *
  825. * Available since libusb-1.0.9.
  826. */
  827. LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3,
  828. };
  829. /** \ingroup asyncio
  830. * Isochronous packet descriptor. */
  831. struct libusb_iso_packet_descriptor {
  832. /** Length of data to request in this packet */
  833. unsigned int length;
  834. /** Amount of data that was actually transferred */
  835. unsigned int actual_length;
  836. /** Status code for this packet */
  837. enum libusb_transfer_status status;
  838. };
  839. struct libusb_transfer;
  840. /** \ingroup asyncio
  841. * Asynchronous transfer callback function type. When submitting asynchronous
  842. * transfers, you pass a pointer to a callback function of this type via the
  843. * \ref libusb_transfer::callback "callback" member of the libusb_transfer
  844. * structure. libusb will call this function later, when the transfer has
  845. * completed or failed. See \ref asyncio for more information.
  846. * \param transfer The libusb_transfer struct the callback function is being
  847. * notified about.
  848. */
  849. typedef void (LIBUSB_CALL *libusb_transfer_cb_fn)(struct libusb_transfer *transfer);
  850. /** \ingroup asyncio
  851. * The generic USB transfer structure. The user populates this structure and
  852. * then submits it in order to request a transfer. After the transfer has
  853. * completed, the library populates the transfer with the results and passes
  854. * it back to the user.
  855. */
  856. struct libusb_transfer {
  857. /** Handle of the device that this transfer will be submitted to */
  858. libusb_device_handle *dev_handle;
  859. /** A bitwise OR combination of \ref libusb_transfer_flags. */
  860. uint8_t flags;
  861. /** Address of the endpoint where this transfer will be sent. */
  862. unsigned char endpoint;
  863. /** Type of the endpoint from \ref libusb_transfer_type */
  864. unsigned char type;
  865. /** Timeout for this transfer in millseconds. A value of 0 indicates no
  866. * timeout. */
  867. unsigned int timeout;
  868. /** The status of the transfer. Read-only, and only for use within
  869. * transfer callback function.
  870. *
  871. * If this is an isochronous transfer, this field may read COMPLETED even
  872. * if there were errors in the frames. Use the
  873. * \ref libusb_iso_packet_descriptor::status "status" field in each packet
  874. * to determine if errors occurred. */
  875. enum libusb_transfer_status status;
  876. /** Length of the data buffer */
  877. int length;
  878. /** Actual length of data that was transferred. Read-only, and only for
  879. * use within transfer callback function. Not valid for isochronous
  880. * endpoint transfers. */
  881. int actual_length;
  882. /** Callback function. This will be invoked when the transfer completes,
  883. * fails, or is cancelled. */
  884. libusb_transfer_cb_fn callback;
  885. /** User context data to pass to the callback function. */
  886. void *user_data;
  887. /** Data buffer */
  888. unsigned char *buffer;
  889. /** Number of isochronous packets. Only used for I/O with isochronous
  890. * endpoints. */
  891. int num_iso_packets;
  892. /** Isochronous packet descriptors, for isochronous transfers only. */
  893. struct libusb_iso_packet_descriptor iso_packet_desc
  894. #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  895. [] /* valid C99 code */
  896. #else
  897. [0] /* non-standard, but usually working code */
  898. #endif
  899. ;
  900. };
  901. /** \ingroup misc
  902. * Capabilities supported by this instance of libusb. Test if the loaded
  903. * library supports a given capability by calling
  904. * \ref libusb_has_capability().
  905. */
  906. enum libusb_capability {
  907. /** The libusb_has_capability() API is available. */
  908. LIBUSB_CAP_HAS_CAPABILITY = 0,
  909. /** The libusb hotplug API is available. */
  910. LIBUSB_CAP_HAS_HOTPLUG = 1,
  911. };
  912. int LIBUSB_CALL libusb_init(libusb_context **ctx);
  913. void LIBUSB_CALL libusb_exit(libusb_context *ctx);
  914. void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
  915. const struct libusb_version * LIBUSB_CALL libusb_get_version(void);
  916. int LIBUSB_CALL libusb_has_capability(uint32_t capability);
  917. const char * LIBUSB_CALL libusb_error_name(int errcode);
  918. const char * LIBUSB_CALL libusb_strerror(enum libusb_error errcode);
  919. ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
  920. libusb_device ***list);
  921. void LIBUSB_CALL libusb_free_device_list(libusb_device **list,
  922. int unref_devices);
  923. libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev);
  924. void LIBUSB_CALL libusb_unref_device(libusb_device *dev);
  925. int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
  926. int *config);
  927. int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,
  928. struct libusb_device_descriptor *desc);
  929. int LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev,
  930. struct libusb_config_descriptor **config);
  931. int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev,
  932. uint8_t config_index, struct libusb_config_descriptor **config);
  933. int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,
  934. uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
  935. void LIBUSB_CALL libusb_free_config_descriptor(
  936. struct libusb_config_descriptor *config);
  937. uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
  938. uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
  939. int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
  940. int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
  941. unsigned char endpoint);
  942. int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
  943. unsigned char endpoint);
  944. int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **handle);
  945. void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle);
  946. libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle);
  947. int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev,
  948. int configuration);
  949. int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev,
  950. int interface_number);
  951. int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev,
  952. int interface_number);
  953. libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid(
  954. libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
  955. int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev,
  956. int interface_number, int alternate_setting);
  957. int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev,
  958. unsigned char endpoint);
  959. int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev);
  960. int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev,
  961. int interface_number);
  962. int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev,
  963. int interface_number);
  964. int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev,
  965. int interface_number);
  966. /* async I/O */
  967. /** \ingroup asyncio
  968. * Get the data section of a control transfer. This convenience function is here
  969. * to remind you that the data does not start until 8 bytes into the actual
  970. * buffer, as the setup packet comes first.
  971. *
  972. * Calling this function only makes sense from a transfer callback function,
  973. * or situations where you have already allocated a suitably sized buffer at
  974. * transfer->buffer.
  975. *
  976. * \param transfer a transfer
  977. * \returns pointer to the first byte of the data section
  978. */
  979. static inline unsigned char *libusb_control_transfer_get_data(
  980. struct libusb_transfer *transfer)
  981. {
  982. return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
  983. }
  984. /** \ingroup asyncio
  985. * Get the control setup packet of a control transfer. This convenience
  986. * function is here to remind you that the control setup occupies the first
  987. * 8 bytes of the transfer data buffer.
  988. *
  989. * Calling this function only makes sense from a transfer callback function,
  990. * or situations where you have already allocated a suitably sized buffer at
  991. * transfer->buffer.
  992. *
  993. * \param transfer a transfer
  994. * \returns a casted pointer to the start of the transfer data buffer
  995. */
  996. static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
  997. struct libusb_transfer *transfer)
  998. {
  999. return (struct libusb_control_setup *) transfer->buffer;
  1000. }
  1001. /** \ingroup asyncio
  1002. * Helper function to populate the setup packet (first 8 bytes of the data
  1003. * buffer) for a control transfer. The wIndex, wValue and wLength values should
  1004. * be given in host-endian byte order.
  1005. *
  1006. * \param buffer buffer to output the setup packet into
  1007. * \param bmRequestType see the
  1008. * \ref libusb_control_setup::bmRequestType "bmRequestType" field of
  1009. * \ref libusb_control_setup
  1010. * \param bRequest see the
  1011. * \ref libusb_control_setup::bRequest "bRequest" field of
  1012. * \ref libusb_control_setup
  1013. * \param wValue see the
  1014. * \ref libusb_control_setup::wValue "wValue" field of
  1015. * \ref libusb_control_setup
  1016. * \param wIndex see the
  1017. * \ref libusb_control_setup::wIndex "wIndex" field of
  1018. * \ref libusb_control_setup
  1019. * \param wLength see the
  1020. * \ref libusb_control_setup::wLength "wLength" field of
  1021. * \ref libusb_control_setup
  1022. */
  1023. static inline void libusb_fill_control_setup(unsigned char *buffer,
  1024. uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
  1025. uint16_t wLength)
  1026. {
  1027. struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
  1028. setup->bmRequestType = bmRequestType;
  1029. setup->bRequest = bRequest;
  1030. setup->wValue = libusb_cpu_to_le16(wValue);
  1031. setup->wIndex = libusb_cpu_to_le16(wIndex);
  1032. setup->wLength = libusb_cpu_to_le16(wLength);
  1033. }
  1034. struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets);
  1035. int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer);
  1036. int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer);
  1037. void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer);
  1038. /** \ingroup asyncio
  1039. * Helper function to populate the required \ref libusb_transfer fields
  1040. * for a control transfer.
  1041. *
  1042. * If you pass a transfer buffer to this function, the first 8 bytes will
  1043. * be interpreted as a control setup packet, and the wLength field will be
  1044. * used to automatically populate the \ref libusb_transfer::length "length"
  1045. * field of the transfer. Therefore the recommended approach is:
  1046. * -# Allocate a suitably sized data buffer (including space for control setup)
  1047. * -# Call libusb_fill_control_setup()
  1048. * -# If this is a host-to-device transfer with a data stage, put the data
  1049. * in place after the setup packet
  1050. * -# Call this function
  1051. * -# Call libusb_submit_transfer()
  1052. *
  1053. * It is also legal to pass a NULL buffer to this function, in which case this
  1054. * function will not attempt to populate the length field. Remember that you
  1055. * must then populate the buffer and length fields later.
  1056. *
  1057. * \param transfer the transfer to populate
  1058. * \param dev_handle handle of the device that will handle the transfer
  1059. * \param buffer data buffer. If provided, this function will interpret the
  1060. * first 8 bytes as a setup packet and infer the transfer length from that.
  1061. * \param callback callback function to be invoked on transfer completion
  1062. * \param user_data user data to pass to callback function
  1063. * \param timeout timeout for the transfer in milliseconds
  1064. */
  1065. static inline void libusb_fill_control_transfer(
  1066. struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
  1067. unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
  1068. unsigned int timeout)
  1069. {
  1070. struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
  1071. transfer->dev_handle = dev_handle;
  1072. transfer->endpoint = 0;
  1073. transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;
  1074. transfer->timeout = timeout;
  1075. transfer->buffer = buffer;
  1076. if (setup)
  1077. transfer->length = LIBUSB_CONTROL_SETUP_SIZE
  1078. + libusb_le16_to_cpu(setup->wLength);
  1079. transfer->user_data = user_data;
  1080. transfer->callback = callback;
  1081. }
  1082. /** \ingroup asyncio
  1083. * Helper function to populate the required \ref libusb_transfer fields
  1084. * for a bulk transfer.
  1085. *
  1086. * \param transfer the transfer to populate
  1087. * \param dev_handle handle of the device that will handle the transfer
  1088. * \param endpoint address of the endpoint where this transfer will be sent
  1089. * \param buffer data buffer
  1090. * \param length length of data buffer
  1091. * \param callback callback function to be invoked on transfer completion
  1092. * \param user_data user data to pass to callback function
  1093. * \param timeout timeout for the transfer in milliseconds
  1094. */
  1095. static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
  1096. libusb_device_handle *dev_handle, unsigned char endpoint,
  1097. unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
  1098. void *user_data, unsigned int timeout)
  1099. {
  1100. transfer->dev_handle = dev_handle;
  1101. transfer->endpoint = endpoint;
  1102. transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
  1103. transfer->timeout = timeout;
  1104. transfer->buffer = buffer;
  1105. transfer->length = length;
  1106. transfer->user_data = user_data;
  1107. transfer->callback = callback;
  1108. }
  1109. /** \ingroup asyncio
  1110. * Helper function to populate the required \ref libusb_transfer fields
  1111. * for an interrupt transfer.
  1112. *
  1113. * \param transfer the transfer to populate
  1114. * \param dev_handle handle of the device that will handle the transfer
  1115. * \param endpoint address of the endpoint where this transfer will be sent
  1116. * \param buffer data buffer
  1117. * \param length length of data buffer
  1118. * \param callback callback function to be invoked on transfer completion
  1119. * \param user_data user data to pass to callback function
  1120. * \param timeout timeout for the transfer in milliseconds
  1121. */
  1122. static inline void libusb_fill_interrupt_transfer(
  1123. struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
  1124. unsigned char endpoint, unsigned char *buffer, int length,
  1125. libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
  1126. {
  1127. transfer->dev_handle = dev_handle;
  1128. transfer->endpoint = endpoint;
  1129. transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;
  1130. transfer->timeout = timeout;
  1131. transfer->buffer = buffer;
  1132. transfer->length = length;
  1133. transfer->user_data = user_data;
  1134. transfer->callback = callback;
  1135. }
  1136. /** \ingroup asyncio
  1137. * Helper function to populate the required \ref libusb_transfer fields
  1138. * for an isochronous transfer.
  1139. *
  1140. * \param transfer the transfer to populate
  1141. * \param dev_handle handle of the device that will handle the transfer
  1142. * \param endpoint address of the endpoint where this transfer will be sent
  1143. * \param buffer data buffer
  1144. * \param length length of data buffer
  1145. * \param num_iso_packets the number of isochronous packets
  1146. * \param callback callback function to be invoked on transfer completion
  1147. * \param user_data user data to pass to callback function
  1148. * \param timeout timeout for the transfer in milliseconds
  1149. */
  1150. static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,
  1151. libusb_device_handle *dev_handle, unsigned char endpoint,
  1152. unsigned char *buffer, int length, int num_iso_packets,
  1153. libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
  1154. {
  1155. transfer->dev_handle = dev_handle;
  1156. transfer->endpoint = endpoint;
  1157. transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
  1158. transfer->timeout = timeout;
  1159. transfer->buffer = buffer;
  1160. transfer->length = length;
  1161. transfer->num_iso_packets = num_iso_packets;
  1162. transfer->user_data = user_data;
  1163. transfer->callback = callback;
  1164. }
  1165. /** \ingroup asyncio
  1166. * Convenience function to set the length of all packets in an isochronous
  1167. * transfer, based on the num_iso_packets field in the transfer structure.
  1168. *
  1169. * \param transfer a transfer
  1170. * \param length the length to set in each isochronous packet descriptor
  1171. * \see libusb_get_max_packet_size()
  1172. */
  1173. static inline void libusb_set_iso_packet_lengths(
  1174. struct libusb_transfer *transfer, unsigned int length)
  1175. {
  1176. int i;
  1177. for (i = 0; i < transfer->num_iso_packets; i++)
  1178. transfer->iso_packet_desc[i].length = length;
  1179. }
  1180. /** \ingroup asyncio
  1181. * Convenience function to locate the position of an isochronous packet
  1182. * within the buffer of an isochronous transfer.
  1183. *
  1184. * This is a thorough function which loops through all preceding packets,
  1185. * accumulating their lengths to find the position of the specified packet.
  1186. * Typically you will assign equal lengths to each packet in the transfer,
  1187. * and hence the above method is sub-optimal. You may wish to use
  1188. * libusb_get_iso_packet_buffer_simple() instead.
  1189. *
  1190. * \param transfer a transfer
  1191. * \param packet the packet to return the address of
  1192. * \returns the base address of the packet buffer inside the transfer buffer,
  1193. * or NULL if the packet does not exist.
  1194. * \see libusb_get_iso_packet_buffer_simple()
  1195. */
  1196. static inline unsigned char *libusb_get_iso_packet_buffer(
  1197. struct libusb_transfer *transfer, unsigned int packet)
  1198. {
  1199. int i;
  1200. size_t offset = 0;
  1201. int _packet;
  1202. /* oops..slight bug in the API. packet is an unsigned int, but we use
  1203. * signed integers almost everywhere else. range-check and convert to
  1204. * signed to avoid compiler warnings. FIXME for libusb-2. */
  1205. if (packet > INT_MAX)
  1206. return NULL;
  1207. _packet = packet;
  1208. if (_packet >= transfer->num_iso_packets)
  1209. return NULL;
  1210. for (i = 0; i < _packet; i++)
  1211. offset += transfer->iso_packet_desc[i].length;
  1212. return transfer->buffer + offset;
  1213. }
  1214. /** \ingroup asyncio
  1215. * Convenience function to locate the position of an isochronous packet
  1216. * within the buffer of an isochronous transfer, for transfers where each
  1217. * packet is of identical size.
  1218. *
  1219. * This function relies on the assumption that every packet within the transfer
  1220. * is of identical size to the first packet. Calculating the location of
  1221. * the packet buffer is then just a simple calculation:
  1222. * <tt>buffer + (packet_size * packet)</tt>
  1223. *
  1224. * Do not use this function on transfers other than those that have identical
  1225. * packet lengths for each packet.
  1226. *
  1227. * \param transfer a transfer
  1228. * \param packet the packet to return the address of
  1229. * \returns the base address of the packet buffer inside the transfer buffer,
  1230. * or NULL if the packet does not exist.
  1231. * \see libusb_get_iso_packet_buffer()
  1232. */
  1233. static inline unsigned char *libusb_get_iso_packet_buffer_simple(
  1234. struct libusb_transfer *transfer, unsigned int packet)
  1235. {
  1236. int _packet;
  1237. /* oops..slight bug in the API. packet is an unsigned int, but we use
  1238. * signed integers almost everywhere else. range-check and convert to
  1239. * signed to avoid compiler warnings. FIXME for libusb-2. */
  1240. if (packet > INT_MAX)
  1241. return NULL;
  1242. _packet = packet;
  1243. if (_packet >= transfer->num_iso_packets)
  1244. return NULL;
  1245. return transfer->buffer + (transfer->iso_packet_desc[0].length * _packet);
  1246. }
  1247. /* sync I/O */
  1248. int LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle,
  1249. uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
  1250. unsigned char *data, uint16_t wLength, unsigned int timeout);
  1251. int LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle,
  1252. unsigned char endpoint, unsigned char *data, int length,
  1253. int *actual_length, unsigned int timeout);
  1254. int LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle,
  1255. unsigned char endpoint, unsigned char *data, int length,
  1256. int *actual_length, unsigned int timeout);
  1257. /** \ingroup desc
  1258. * Retrieve a descriptor from the default control pipe.
  1259. * This is a convenience function which formulates the appropriate control
  1260. * message to retrieve the descriptor.
  1261. *
  1262. * \param dev a device handle
  1263. * \param desc_type the descriptor type, see \ref libusb_descriptor_type
  1264. * \param desc_index the index of the descriptor to retrieve
  1265. * \param data output buffer for descriptor
  1266. * \param length size of data buffer
  1267. * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
  1268. */
  1269. static inline int libusb_get_descriptor(libusb_device_handle *dev,
  1270. uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length)
  1271. {
  1272. return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
  1273. LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data,
  1274. (uint16_t) length, 1000);
  1275. }
  1276. /** \ingroup desc
  1277. * Retrieve a descriptor from a device.
  1278. * This is a convenience function which formulates the appropriate control
  1279. * message to retrieve the descriptor. The string returned is Unicode, as
  1280. * detailed in the USB specifications.
  1281. *
  1282. * \param dev a device handle
  1283. * \param desc_index the index of the descriptor to retrieve
  1284. * \param langid the language ID for the string descriptor
  1285. * \param data output buffer for descriptor
  1286. * \param length size of data buffer
  1287. * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
  1288. * \see libusb_get_string_descriptor_ascii()
  1289. */
  1290. static inline int libusb_get_string_descriptor(libusb_device_handle *dev,
  1291. uint8_t desc_index, uint16_t langid, unsigned char *data, int length)
  1292. {
  1293. return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
  1294. LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t)((LIBUSB_DT_STRING << 8) | desc_index),
  1295. langid, data, (uint16_t) length, 1000);
  1296. }
  1297. int LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
  1298. uint8_t desc_index, unsigned char *data, int length);
  1299. /* polling and timeouts */
  1300. int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx);
  1301. void LIBUSB_CALL libusb_lock_events(libusb_context *ctx);
  1302. void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx);
  1303. int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx);
  1304. int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx);
  1305. void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx);
  1306. void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx);
  1307. int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);
  1308. int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,
  1309. struct timeval *tv);
  1310. int LIBUSB_CALL libusb_handle_events_timeout_completed(libusb_context *ctx,
  1311. struct timeval *tv, int *completed);
  1312. int LIBUSB_CALL libusb_handle_events(libusb_context *ctx);
  1313. int LIBUSB_CALL libusb_handle_events_completed(libusb_context *ctx, int *completed);
  1314. int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
  1315. struct timeval *tv);
  1316. int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx);
  1317. int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
  1318. struct timeval *tv);
  1319. /** \ingroup poll
  1320. * File descriptor for polling
  1321. */
  1322. struct libusb_pollfd {
  1323. /** Numeric file descriptor */
  1324. int fd;
  1325. /** Event flags to poll for from <poll.h>. POLLIN indicates that you
  1326. * should monitor this file descriptor for becoming ready to read from,
  1327. * and POLLOUT indicates that you should monitor this file descriptor for
  1328. * nonblocking write readiness. */
  1329. short events;
  1330. };
  1331. /** \ingroup poll
  1332. * Callback function, invoked when a new file descriptor should be added
  1333. * to the set of file descriptors monitored for events.
  1334. * \param fd the new file descriptor
  1335. * \param events events to monitor for, see \ref libusb_pollfd for a
  1336. * description
  1337. * \param user_data User data pointer specified in
  1338. * libusb_set_pollfd_notifiers() call
  1339. * \see libusb_set_pollfd_notifiers()
  1340. */
  1341. typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events,
  1342. void *user_data);
  1343. /** \ingroup poll
  1344. * Callback function, invoked when a file descriptor should be removed from
  1345. * the set of file descriptors being monitored for events. After returning
  1346. * from this callback, do not use that file descriptor again.
  1347. * \param fd the file descriptor to stop monitoring
  1348. * \param user_data User data pointer specified in
  1349. * libusb_set_pollfd_notifiers() call
  1350. * \see libusb_set_pollfd_notifiers()
  1351. */
  1352. typedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(int fd, void *user_data);
  1353. const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(
  1354. libusb_context *ctx);
  1355. void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
  1356. libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
  1357. void *user_data);
  1358. /** \ingroup desc
  1359. * Parse a USB 3.0 endpoint companion descriptor.
  1360. *
  1361. * \param[in] buf the buffer containing the endpoint companion descriptor
  1362. * \param[in] len the length of the buffer
  1363. * \param[out] ep_comp a parsed endpoint companion descriptor. must be freed by
  1364. * libusb_free_ss_endpoint_comp()
  1365. *
  1366. * \returns LIBUSB_SUCCESS on success
  1367. * \returns LIBUSB_ERROR code on error
  1368. */
  1369. int LIBUSB_CALL libusb_parse_ss_endpoint_comp(const void *buf, int len,
  1370. struct libusb_ss_endpoint_companion_descriptor **ep_comp);
  1371. /** \ingroup desc
  1372. * Free a USB 3.0 endpoint companion descriptor.
  1373. *
  1374. * \param[in] ep_comp the descriptor to free
  1375. */
  1376. void LIBUSB_CALL libusb_free_ss_endpoint_comp(struct libusb_ss_endpoint_companion_descriptor *ep_comp);
  1377. /** \ingroup desc
  1378. * Parse a Binary Object Store (BOS) descriptor.
  1379. *
  1380. * \param[in] buf the buffer containing the BOS descriptor
  1381. * \param[in] len the length of the buffer
  1382. * \param[out] bos a parsed BOS descriptor. must be freed by
  1383. * libusb_free_bos_descriptor()
  1384. *
  1385. * \returns LIBUSB_SUCCESS on success
  1386. * \returns LIBUSB_ERROR code on error
  1387. */
  1388. int LIBUSB_CALL libusb_parse_bos_descriptor(const void *buf, int len,
  1389. struct libusb_bos_descriptor **bos);
  1390. /** \ingroup desc
  1391. * Free a Binary Object Store (BOS) descriptor.
  1392. *
  1393. * \param[in] bos the descriptor to free
  1394. */
  1395. void LIBUSB_CALL libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos);
  1396. /** \ingroup hotplug
  1397. * Callback handle.
  1398. *
  1399. * Callbacks handles are generated by libusb_hotplug_register_callback()
  1400. * and can be used to deregister callbacks. Callback handles are unique
  1401. * per libusb_context and it is safe to call libusb_hotplug_deregister_callback()
  1402. * on an already deregisted callback.
  1403. *
  1404. * For more information, see \ref hotplug.
  1405. */
  1406. typedef int libusb_hotplug_callback_handle;
  1407. /** \ingroup hotplug
  1408. * Flags for hotplug events */
  1409. typedef enum {
  1410. /** Arm the callback and fire it for all matching currently attached devices. */
  1411. LIBUSB_HOTPLUG_ENUMERATE = 1,
  1412. } libusb_hotplug_flag;
  1413. /** \ingroup hotplug
  1414. * Hotplug events */
  1415. typedef enum {
  1416. /** A device has been plugged in and is ready to use */
  1417. LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01,
  1418. /** A device has left and is no longer available.
  1419. * It is the user's responsibility to call libusb_close on any handle associated with a disconnected device.
  1420. * It is safe to call libusb_get_device_descriptor on a device that has left */
  1421. LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02,
  1422. } libusb_hotplug_event;
  1423. /** \ingroup hotplug
  1424. * Wildcard matching for hotplug events */
  1425. #define LIBUSB_HOTPLUG_MATCH_ANY -1
  1426. /** \ingroup hotplug
  1427. * Hotplug callback function type. When requesting hotplug event notifications,
  1428. * you pass a pointer to a callback function of this type.
  1429. *
  1430. * This callback may be called by an internal event thread and as such it is
  1431. * recommended the callback do minimal processing before returning.
  1432. *
  1433. * libusb will call this function later, when a matching event had happened on
  1434. * a matching device. See \ref hotplug for more information.
  1435. *
  1436. * It is safe to call either libusb_hotplug_register_callback() or
  1437. * libusb_hotplug_deregister_callback() from within a callback function.
  1438. *
  1439. * \param libusb_context context of this notification
  1440. * \param device libusb_device this event occurred on
  1441. * \param event event that occurred
  1442. * \param user_data user data provided when this callback was registered
  1443. * \returns bool whether this callback is finished processing events.
  1444. * returning 1 will cause this callback to be deregistered
  1445. */
  1446. typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx,
  1447. libusb_device *device,
  1448. libusb_hotplug_event event,
  1449. void *user_data);
  1450. /** \ingroup hotplug
  1451. * Register a hotplug callback function
  1452. *
  1453. * Register a callback with the libusb_context. The callback will fire
  1454. * when a matching event occurs on a matching device. The callback is
  1455. * armed until either it is deregistered with libusb_hotplug_deregister_callback()
  1456. * or the supplied callback returns 1 to indicate it is finished processing events.
  1457. *
  1458. * \param[in] ctx context to register this callback with
  1459. * \param[in] events bitwise or of events that will trigger this callback. See \ref
  1460. * libusb_hotplug_event
  1461. * \param[in] flags hotplug callback flags. See \ref libusb_hotplug_flag
  1462. * \param[in] vendor_id the vendor id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY
  1463. * \param[in] product_id the product id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY
  1464. * \param[in] dev_class the device class to match or \ref LIBUSB_HOTPLUG_MATCH_ANY
  1465. * \param[in] cb_fn the function to be invoked on a matching event/device
  1466. * \param[in] user_data user data to pass to the callback function
  1467. * \param[out] handle pointer to store the handle of the allocated callback (can be NULL)
  1468. * \returns LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure
  1469. */
  1470. int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx,
  1471. libusb_hotplug_event events,
  1472. libusb_hotplug_flag flags,
  1473. int vendor_id, int product_id,
  1474. int dev_class,
  1475. libusb_hotplug_callback_fn cb_fn,
  1476. void *user_data,
  1477. libusb_hotplug_callback_handle *handle);
  1478. /** \ingroup hotplug
  1479. * Deregisters a hotplug callback.
  1480. *
  1481. * Deregister a callback from a libusb_context. This function is safe to call from within
  1482. * a hotplug callback.
  1483. *
  1484. * \param[in] ctx context this callback is registered with
  1485. * \param[in] handle the handle of the callback to deregister
  1486. */
  1487. void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx,
  1488. libusb_hotplug_callback_handle handle);
  1489. #ifdef __cplusplus
  1490. }
  1491. #endif
  1492. #endif