libusb.h 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142
  1. /*
  2. * Public libusb header file
  3. * Copyright © 2001 Johannes Erdfelt <johannes@erdfelt.com>
  4. * Copyright © 2007-2008 Daniel Drake <dsd@gentoo.org>
  5. * Copyright © 2012 Pete Batard <pete@akeo.ie>
  6. * Copyright © 2012-2018 Nathan Hjelm <hjelmn@cs.unm.edu>
  7. * Copyright © 2014-2020 Chris Dickens <christopher.a.dickens@gmail.com>
  8. * For more information, please visit: http://libusb.info
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #ifndef LIBUSB_H
  25. #define LIBUSB_H
  26. #if defined(_MSC_VER)
  27. #pragma warning(push)
  28. /* Disable: warning C4200: nonstandard extension used : zero-sized array in struct/union */
  29. #pragma warning(disable:4200)
  30. /* on MS environments, the inline keyword is available in C++ only */
  31. #if !defined(__cplusplus)
  32. #define inline __inline
  33. #endif
  34. /* ssize_t is also not available */
  35. #ifndef _SSIZE_T_DEFINED
  36. #define _SSIZE_T_DEFINED
  37. #include <basetsd.h>
  38. typedef SSIZE_T ssize_t;
  39. #endif /* _SSIZE_T_DEFINED */
  40. #endif /* _MSC_VER */
  41. #include <limits.h>
  42. #include <stdint.h>
  43. #include <sys/types.h>
  44. #if !defined(_MSC_VER)
  45. #include <sys/time.h>
  46. #endif
  47. #include <time.h>
  48. #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  49. #define ZERO_SIZED_ARRAY /* [] - valid C99 code */
  50. #else
  51. #define ZERO_SIZED_ARRAY 0 /* [0] - non-standard, but usually working code */
  52. #endif /* __STDC_VERSION__ */
  53. /* 'interface' might be defined as a macro on Windows, so we need to
  54. * undefine it so as not to break the current libusb API, because
  55. * libusb_config_descriptor has an 'interface' member
  56. * As this can be problematic if you include windows.h after libusb.h
  57. * in your sources, we force windows.h to be included first. */
  58. #if defined(_WIN32) || defined(__CYGWIN__)
  59. #include <windows.h>
  60. #if defined(interface)
  61. #undef interface
  62. #endif
  63. #if !defined(__CYGWIN__)
  64. #include <winsock.h>
  65. #endif
  66. #endif /* _WIN32 || __CYGWIN__ */
  67. #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
  68. #define LIBUSB_DEPRECATED_FOR(f) __attribute__ ((deprecated ("Use " #f " instead")))
  69. #elif defined(__GNUC__) && (__GNUC__ >= 3)
  70. #define LIBUSB_DEPRECATED_FOR(f) __attribute__ ((deprecated))
  71. #else
  72. #define LIBUSB_DEPRECATED_FOR(f)
  73. #endif /* __GNUC__ */
  74. #if defined(__GNUC__)
  75. #define LIBUSB_PACKED __attribute__ ((packed))
  76. #else
  77. #define LIBUSB_PACKED
  78. #endif /* __GNUC__ */
  79. /** \def LIBUSB_CALL
  80. * \ingroup libusb_misc
  81. * libusb's Windows calling convention.
  82. *
  83. * Under Windows, the selection of available compilers and configurations
  84. * means that, unlike other platforms, there is not <em>one true calling
  85. * convention</em> (calling convention: the manner in which parameters are
  86. * passed to functions in the generated assembly code).
  87. *
  88. * Matching the Windows API itself, libusb uses the WINAPI convention (which
  89. * translates to the <tt>stdcall</tt> convention) and guarantees that the
  90. * library is compiled in this way. The public header file also includes
  91. * appropriate annotations so that your own software will use the right
  92. * convention, even if another convention is being used by default within
  93. * your codebase.
  94. *
  95. * The one consideration that you must apply in your software is to mark
  96. * all functions which you use as libusb callbacks with this LIBUSB_CALL
  97. * annotation, so that they too get compiled for the correct calling
  98. * convention.
  99. *
  100. * On non-Windows operating systems, this macro is defined as nothing. This
  101. * means that you can apply it to your code without worrying about
  102. * cross-platform compatibility.
  103. */
  104. /* LIBUSB_CALL must be defined on both definition and declaration of libusb
  105. * functions. You'd think that declaration would be enough, but cygwin will
  106. * complain about conflicting types unless both are marked this way.
  107. * The placement of this macro is important too; it must appear after the
  108. * return type, before the function name. See internal documentation for
  109. * API_EXPORTED.
  110. */
  111. #if defined(_WIN32) || defined(__CYGWIN__)
  112. #define LIBUSB_CALL WINAPI
  113. #else
  114. #define LIBUSB_CALL
  115. #endif /* _WIN32 || __CYGWIN__ */
  116. /** \def LIBUSB_API_VERSION
  117. * \ingroup libusb_misc
  118. * libusb's API version.
  119. *
  120. * Since version 1.0.13, to help with feature detection, libusb defines
  121. * a LIBUSB_API_VERSION macro that gets increased every time there is a
  122. * significant change to the API, such as the introduction of a new call,
  123. * the definition of a new macro/enum member, or any other element that
  124. * libusb applications may want to detect at compilation time.
  125. *
  126. * The macro is typically used in an application as follows:
  127. * \code
  128. * #if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01001234)
  129. * // Use one of the newer features from the libusb API
  130. * #endif
  131. * \endcode
  132. *
  133. * Internally, LIBUSB_API_VERSION is defined as follows:
  134. * (libusb major << 24) | (libusb minor << 16) | (16 bit incremental)
  135. */
  136. #define LIBUSB_API_VERSION 0x01000109
  137. /* The following is kept for compatibility, but will be deprecated in the future */
  138. #define LIBUSBX_API_VERSION LIBUSB_API_VERSION
  139. #if defined(__cplusplus)
  140. extern "C" {
  141. #endif
  142. /**
  143. * \ingroup libusb_misc
  144. * Convert a 16-bit value from host-endian to little-endian format. On
  145. * little endian systems, this function does nothing. On big endian systems,
  146. * the bytes are swapped.
  147. * \param x the host-endian value to convert
  148. * \returns the value in little-endian byte order
  149. */
  150. static inline uint16_t libusb_cpu_to_le16(const uint16_t x)
  151. {
  152. union {
  153. uint8_t b8[2];
  154. uint16_t b16;
  155. } _tmp;
  156. _tmp.b8[1] = (uint8_t) (x >> 8);
  157. _tmp.b8[0] = (uint8_t) (x & 0xff);
  158. return _tmp.b16;
  159. }
  160. /** \def libusb_le16_to_cpu
  161. * \ingroup libusb_misc
  162. * Convert a 16-bit value from little-endian to host-endian format. On
  163. * little endian systems, this function does nothing. On big endian systems,
  164. * the bytes are swapped.
  165. * \param x the little-endian value to convert
  166. * \returns the value in host-endian byte order
  167. */
  168. #define libusb_le16_to_cpu libusb_cpu_to_le16
  169. /* standard USB stuff */
  170. /** \ingroup libusb_desc
  171. * Device and/or Interface Class codes */
  172. enum libusb_class_code {
  173. /** In the context of a \ref libusb_device_descriptor "device descriptor",
  174. * this bDeviceClass value indicates that each interface specifies its
  175. * own class information and all interfaces operate independently.
  176. */
  177. LIBUSB_CLASS_PER_INTERFACE = 0x00,
  178. /** Audio class */
  179. LIBUSB_CLASS_AUDIO = 0x01,
  180. /** Communications class */
  181. LIBUSB_CLASS_COMM = 0x02,
  182. /** Human Interface Device class */
  183. LIBUSB_CLASS_HID = 0x03,
  184. /** Physical */
  185. LIBUSB_CLASS_PHYSICAL = 0x05,
  186. /** Image class */
  187. LIBUSB_CLASS_IMAGE = 0x06,
  188. LIBUSB_CLASS_PTP = 0x06, /* legacy name from libusb-0.1 usb.h */
  189. /** Printer class */
  190. LIBUSB_CLASS_PRINTER = 0x07,
  191. /** Mass storage class */
  192. LIBUSB_CLASS_MASS_STORAGE = 0x08,
  193. /** Hub class */
  194. LIBUSB_CLASS_HUB = 0x09,
  195. /** Data class */
  196. LIBUSB_CLASS_DATA = 0x0a,
  197. /** Smart Card */
  198. LIBUSB_CLASS_SMART_CARD = 0x0b,
  199. /** Content Security */
  200. LIBUSB_CLASS_CONTENT_SECURITY = 0x0d,
  201. /** Video */
  202. LIBUSB_CLASS_VIDEO = 0x0e,
  203. /** Personal Healthcare */
  204. LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
  205. /** Diagnostic Device */
  206. LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
  207. /** Wireless class */
  208. LIBUSB_CLASS_WIRELESS = 0xe0,
  209. /** Miscellaneous class */
  210. LIBUSB_CLASS_MISCELLANEOUS = 0xef,
  211. /** Application class */
  212. LIBUSB_CLASS_APPLICATION = 0xfe,
  213. /** Class is vendor-specific */
  214. LIBUSB_CLASS_VENDOR_SPEC = 0xff
  215. };
  216. /** \ingroup libusb_desc
  217. * Descriptor types as defined by the USB specification. */
  218. enum libusb_descriptor_type {
  219. /** Device descriptor. See libusb_device_descriptor. */
  220. LIBUSB_DT_DEVICE = 0x01,
  221. /** Configuration descriptor. See libusb_config_descriptor. */
  222. LIBUSB_DT_CONFIG = 0x02,
  223. /** String descriptor */
  224. LIBUSB_DT_STRING = 0x03,
  225. /** Interface descriptor. See libusb_interface_descriptor. */
  226. LIBUSB_DT_INTERFACE = 0x04,
  227. /** Endpoint descriptor. See libusb_endpoint_descriptor. */
  228. LIBUSB_DT_ENDPOINT = 0x05,
  229. /** BOS descriptor */
  230. LIBUSB_DT_BOS = 0x0f,
  231. /** Device Capability descriptor */
  232. LIBUSB_DT_DEVICE_CAPABILITY = 0x10,
  233. /** HID descriptor */
  234. LIBUSB_DT_HID = 0x21,
  235. /** HID report descriptor */
  236. LIBUSB_DT_REPORT = 0x22,
  237. /** Physical descriptor */
  238. LIBUSB_DT_PHYSICAL = 0x23,
  239. /** Hub descriptor */
  240. LIBUSB_DT_HUB = 0x29,
  241. /** SuperSpeed Hub descriptor */
  242. LIBUSB_DT_SUPERSPEED_HUB = 0x2a,
  243. /** SuperSpeed Endpoint Companion descriptor */
  244. LIBUSB_DT_SS_ENDPOINT_COMPANION = 0x30
  245. };
  246. /* Descriptor sizes per descriptor type */
  247. #define LIBUSB_DT_DEVICE_SIZE 18
  248. #define LIBUSB_DT_CONFIG_SIZE 9
  249. #define LIBUSB_DT_INTERFACE_SIZE 9
  250. #define LIBUSB_DT_ENDPOINT_SIZE 7
  251. #define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
  252. #define LIBUSB_DT_HUB_NONVAR_SIZE 7
  253. #define LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE 6
  254. #define LIBUSB_DT_BOS_SIZE 5
  255. #define LIBUSB_DT_DEVICE_CAPABILITY_SIZE 3
  256. /* BOS descriptor sizes */
  257. #define LIBUSB_BT_USB_2_0_EXTENSION_SIZE 7
  258. #define LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE 10
  259. #define LIBUSB_BT_CONTAINER_ID_SIZE 20
  260. /* We unwrap the BOS => define its max size */
  261. #define LIBUSB_DT_BOS_MAX_SIZE \
  262. (LIBUSB_DT_BOS_SIZE + \
  263. LIBUSB_BT_USB_2_0_EXTENSION_SIZE + \
  264. LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE + \
  265. LIBUSB_BT_CONTAINER_ID_SIZE)
  266. #define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
  267. #define LIBUSB_ENDPOINT_DIR_MASK 0x80
  268. /** \ingroup libusb_desc
  269. * Endpoint direction. Values for bit 7 of the
  270. * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
  271. */
  272. enum libusb_endpoint_direction {
  273. /** Out: host-to-device */
  274. LIBUSB_ENDPOINT_OUT = 0x00,
  275. /** In: device-to-host */
  276. LIBUSB_ENDPOINT_IN = 0x80
  277. };
  278. #define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */
  279. /** \ingroup libusb_desc
  280. * Endpoint transfer type. Values for bits 0:1 of the
  281. * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
  282. */
  283. enum libusb_endpoint_transfer_type {
  284. /** Control endpoint */
  285. LIBUSB_ENDPOINT_TRANSFER_TYPE_CONTROL = 0x0,
  286. /** Isochronous endpoint */
  287. LIBUSB_ENDPOINT_TRANSFER_TYPE_ISOCHRONOUS = 0x1,
  288. /** Bulk endpoint */
  289. LIBUSB_ENDPOINT_TRANSFER_TYPE_BULK = 0x2,
  290. /** Interrupt endpoint */
  291. LIBUSB_ENDPOINT_TRANSFER_TYPE_INTERRUPT = 0x3
  292. };
  293. /** \ingroup libusb_misc
  294. * Standard requests, as defined in table 9-5 of the USB 3.0 specifications */
  295. enum libusb_standard_request {
  296. /** Request status of the specific recipient */
  297. LIBUSB_REQUEST_GET_STATUS = 0x00,
  298. /** Clear or disable a specific feature */
  299. LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
  300. /* 0x02 is reserved */
  301. /** Set or enable a specific feature */
  302. LIBUSB_REQUEST_SET_FEATURE = 0x03,
  303. /* 0x04 is reserved */
  304. /** Set device address for all future accesses */
  305. LIBUSB_REQUEST_SET_ADDRESS = 0x05,
  306. /** Get the specified descriptor */
  307. LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
  308. /** Used to update existing descriptors or add new descriptors */
  309. LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
  310. /** Get the current device configuration value */
  311. LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
  312. /** Set device configuration */
  313. LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
  314. /** Return the selected alternate setting for the specified interface */
  315. LIBUSB_REQUEST_GET_INTERFACE = 0x0a,
  316. /** Select an alternate interface for the specified interface */
  317. LIBUSB_REQUEST_SET_INTERFACE = 0x0b,
  318. /** Set then report an endpoint's synchronization frame */
  319. LIBUSB_REQUEST_SYNCH_FRAME = 0x0c,
  320. /** Sets both the U1 and U2 Exit Latency */
  321. LIBUSB_REQUEST_SET_SEL = 0x30,
  322. /** Delay from the time a host transmits a packet to the time it is
  323. * received by the device. */
  324. LIBUSB_SET_ISOCH_DELAY = 0x31
  325. };
  326. /** \ingroup libusb_misc
  327. * Request type bits of the
  328. * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
  329. * transfers. */
  330. enum libusb_request_type {
  331. /** Standard */
  332. LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
  333. /** Class */
  334. LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
  335. /** Vendor */
  336. LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
  337. /** Reserved */
  338. LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)
  339. };
  340. /** \ingroup libusb_misc
  341. * Recipient bits of the
  342. * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
  343. * transfers. Values 4 through 31 are reserved. */
  344. enum libusb_request_recipient {
  345. /** Device */
  346. LIBUSB_RECIPIENT_DEVICE = 0x00,
  347. /** Interface */
  348. LIBUSB_RECIPIENT_INTERFACE = 0x01,
  349. /** Endpoint */
  350. LIBUSB_RECIPIENT_ENDPOINT = 0x02,
  351. /** Other */
  352. LIBUSB_RECIPIENT_OTHER = 0x03
  353. };
  354. #define LIBUSB_ISO_SYNC_TYPE_MASK 0x0c
  355. /** \ingroup libusb_desc
  356. * Synchronization type for isochronous endpoints. Values for bits 2:3 of the
  357. * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
  358. * libusb_endpoint_descriptor.
  359. */
  360. enum libusb_iso_sync_type {
  361. /** No synchronization */
  362. LIBUSB_ISO_SYNC_TYPE_NONE = 0x0,
  363. /** Asynchronous */
  364. LIBUSB_ISO_SYNC_TYPE_ASYNC = 0x1,
  365. /** Adaptive */
  366. LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 0x2,
  367. /** Synchronous */
  368. LIBUSB_ISO_SYNC_TYPE_SYNC = 0x3
  369. };
  370. #define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
  371. /** \ingroup libusb_desc
  372. * Usage type for isochronous endpoints. Values for bits 4:5 of the
  373. * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
  374. * libusb_endpoint_descriptor.
  375. */
  376. enum libusb_iso_usage_type {
  377. /** Data endpoint */
  378. LIBUSB_ISO_USAGE_TYPE_DATA = 0x0,
  379. /** Feedback endpoint */
  380. LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 0x1,
  381. /** Implicit feedback Data endpoint */
  382. LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 0x2
  383. };
  384. /** \ingroup libusb_desc
  385. * Supported speeds (wSpeedSupported) bitfield. Indicates what
  386. * speeds the device supports.
  387. */
  388. enum libusb_supported_speed {
  389. /** Low speed operation supported (1.5MBit/s). */
  390. LIBUSB_LOW_SPEED_OPERATION = (1 << 0),
  391. /** Full speed operation supported (12MBit/s). */
  392. LIBUSB_FULL_SPEED_OPERATION = (1 << 1),
  393. /** High speed operation supported (480MBit/s). */
  394. LIBUSB_HIGH_SPEED_OPERATION = (1 << 2),
  395. /** Superspeed operation supported (5000MBit/s). */
  396. LIBUSB_SUPER_SPEED_OPERATION = (1 << 3)
  397. };
  398. /** \ingroup libusb_desc
  399. * Masks for the bits of the
  400. * \ref libusb_usb_2_0_extension_descriptor::bmAttributes "bmAttributes" field
  401. * of the USB 2.0 Extension descriptor.
  402. */
  403. enum libusb_usb_2_0_extension_attributes {
  404. /** Supports Link Power Management (LPM) */
  405. LIBUSB_BM_LPM_SUPPORT = (1 << 1)
  406. };
  407. /** \ingroup libusb_desc
  408. * Masks for the bits of the
  409. * \ref libusb_ss_usb_device_capability_descriptor::bmAttributes "bmAttributes" field
  410. * field of the SuperSpeed USB Device Capability descriptor.
  411. */
  412. enum libusb_ss_usb_device_capability_attributes {
  413. /** Supports Latency Tolerance Messages (LTM) */
  414. LIBUSB_BM_LTM_SUPPORT = (1 << 1)
  415. };
  416. /** \ingroup libusb_desc
  417. * USB capability types
  418. */
  419. enum libusb_bos_type {
  420. /** Wireless USB device capability */
  421. LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 0x01,
  422. /** USB 2.0 extensions */
  423. LIBUSB_BT_USB_2_0_EXTENSION = 0x02,
  424. /** SuperSpeed USB device capability */
  425. LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 0x03,
  426. /** Container ID type */
  427. LIBUSB_BT_CONTAINER_ID = 0x04
  428. };
  429. /** \ingroup libusb_desc
  430. * A structure representing the standard USB device descriptor. This
  431. * descriptor is documented in section 9.6.1 of the USB 3.0 specification.
  432. * All multiple-byte fields are represented in host-endian format.
  433. */
  434. struct libusb_device_descriptor {
  435. /** Size of this descriptor (in bytes) */
  436. uint8_t bLength;
  437. /** Descriptor type. Will have value
  438. * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this
  439. * context. */
  440. uint8_t bDescriptorType;
  441. /** USB specification release number in binary-coded decimal. A value of
  442. * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
  443. uint16_t bcdUSB;
  444. /** USB-IF class code for the device. See \ref libusb_class_code. */
  445. uint8_t bDeviceClass;
  446. /** USB-IF subclass code for the device, qualified by the bDeviceClass
  447. * value */
  448. uint8_t bDeviceSubClass;
  449. /** USB-IF protocol code for the device, qualified by the bDeviceClass and
  450. * bDeviceSubClass values */
  451. uint8_t bDeviceProtocol;
  452. /** Maximum packet size for endpoint 0 */
  453. uint8_t bMaxPacketSize0;
  454. /** USB-IF vendor ID */
  455. uint16_t idVendor;
  456. /** USB-IF product ID */
  457. uint16_t idProduct;
  458. /** Device release number in binary-coded decimal */
  459. uint16_t bcdDevice;
  460. /** Index of string descriptor describing manufacturer */
  461. uint8_t iManufacturer;
  462. /** Index of string descriptor describing product */
  463. uint8_t iProduct;
  464. /** Index of string descriptor containing device serial number */
  465. uint8_t iSerialNumber;
  466. /** Number of possible configurations */
  467. uint8_t bNumConfigurations;
  468. };
  469. /** \ingroup libusb_desc
  470. * A structure representing the standard USB endpoint descriptor. This
  471. * descriptor is documented in section 9.6.6 of the USB 3.0 specification.
  472. * All multiple-byte fields are represented in host-endian format.
  473. */
  474. struct libusb_endpoint_descriptor {
  475. /** Size of this descriptor (in bytes) */
  476. uint8_t bLength;
  477. /** Descriptor type. Will have value
  478. * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in
  479. * this context. */
  480. uint8_t bDescriptorType;
  481. /** The address of the endpoint described by this descriptor. Bits 0:3 are
  482. * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,
  483. * see \ref libusb_endpoint_direction. */
  484. uint8_t bEndpointAddress;
  485. /** Attributes which apply to the endpoint when it is configured using
  486. * the bConfigurationValue. Bits 0:1 determine the transfer type and
  487. * correspond to \ref libusb_endpoint_transfer_type. Bits 2:3 are only used
  488. * for isochronous endpoints and correspond to \ref libusb_iso_sync_type.
  489. * Bits 4:5 are also only used for isochronous endpoints and correspond to
  490. * \ref libusb_iso_usage_type. Bits 6:7 are reserved. */
  491. uint8_t bmAttributes;
  492. /** Maximum packet size this endpoint is capable of sending/receiving. */
  493. uint16_t wMaxPacketSize;
  494. /** Interval for polling endpoint for data transfers. */
  495. uint8_t bInterval;
  496. /** For audio devices only: the rate at which synchronization feedback
  497. * is provided. */
  498. uint8_t bRefresh;
  499. /** For audio devices only: the address if the synch endpoint */
  500. uint8_t bSynchAddress;
  501. /** Extra descriptors. If libusb encounters unknown endpoint descriptors,
  502. * it will store them here, should you wish to parse them. */
  503. const unsigned char *extra;
  504. /** Length of the extra descriptors, in bytes. Must be non-negative. */
  505. int extra_length;
  506. };
  507. /** \ingroup libusb_desc
  508. * A structure representing the standard USB interface descriptor. This
  509. * descriptor is documented in section 9.6.5 of the USB 3.0 specification.
  510. * All multiple-byte fields are represented in host-endian format.
  511. */
  512. struct libusb_interface_descriptor {
  513. /** Size of this descriptor (in bytes) */
  514. uint8_t bLength;
  515. /** Descriptor type. Will have value
  516. * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE
  517. * in this context. */
  518. uint8_t bDescriptorType;
  519. /** Number of this interface */
  520. uint8_t bInterfaceNumber;
  521. /** Value used to select this alternate setting for this interface */
  522. uint8_t bAlternateSetting;
  523. /** Number of endpoints used by this interface (excluding the control
  524. * endpoint). */
  525. uint8_t bNumEndpoints;
  526. /** USB-IF class code for this interface. See \ref libusb_class_code. */
  527. uint8_t bInterfaceClass;
  528. /** USB-IF subclass code for this interface, qualified by the
  529. * bInterfaceClass value */
  530. uint8_t bInterfaceSubClass;
  531. /** USB-IF protocol code for this interface, qualified by the
  532. * bInterfaceClass and bInterfaceSubClass values */
  533. uint8_t bInterfaceProtocol;
  534. /** Index of string descriptor describing this interface */
  535. uint8_t iInterface;
  536. /** Array of endpoint descriptors. This length of this array is determined
  537. * by the bNumEndpoints field. */
  538. const struct libusb_endpoint_descriptor *endpoint;
  539. /** Extra descriptors. If libusb encounters unknown interface descriptors,
  540. * it will store them here, should you wish to parse them. */
  541. const unsigned char *extra;
  542. /** Length of the extra descriptors, in bytes. Must be non-negative. */
  543. int extra_length;
  544. };
  545. /** \ingroup libusb_desc
  546. * A collection of alternate settings for a particular USB interface.
  547. */
  548. struct libusb_interface {
  549. /** Array of interface descriptors. The length of this array is determined
  550. * by the num_altsetting field. */
  551. const struct libusb_interface_descriptor *altsetting;
  552. /** The number of alternate settings that belong to this interface.
  553. * Must be non-negative. */
  554. int num_altsetting;
  555. };
  556. /** \ingroup libusb_desc
  557. * A structure representing the standard USB configuration descriptor. This
  558. * descriptor is documented in section 9.6.3 of the USB 3.0 specification.
  559. * All multiple-byte fields are represented in host-endian format.
  560. */
  561. struct libusb_config_descriptor {
  562. /** Size of this descriptor (in bytes) */
  563. uint8_t bLength;
  564. /** Descriptor type. Will have value
  565. * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG
  566. * in this context. */
  567. uint8_t bDescriptorType;
  568. /** Total length of data returned for this configuration */
  569. uint16_t wTotalLength;
  570. /** Number of interfaces supported by this configuration */
  571. uint8_t bNumInterfaces;
  572. /** Identifier value for this configuration */
  573. uint8_t bConfigurationValue;
  574. /** Index of string descriptor describing this configuration */
  575. uint8_t iConfiguration;
  576. /** Configuration characteristics */
  577. uint8_t bmAttributes;
  578. /** Maximum power consumption of the USB device from this bus in this
  579. * configuration when the device is fully operation. Expressed in units
  580. * of 2 mA when the device is operating in high-speed mode and in units
  581. * of 8 mA when the device is operating in super-speed mode. */
  582. uint8_t MaxPower;
  583. /** Array of interfaces supported by this configuration. The length of
  584. * this array is determined by the bNumInterfaces field. */
  585. const struct libusb_interface *interface;
  586. /** Extra descriptors. If libusb encounters unknown configuration
  587. * descriptors, it will store them here, should you wish to parse them. */
  588. const unsigned char *extra;
  589. /** Length of the extra descriptors, in bytes. Must be non-negative. */
  590. int extra_length;
  591. };
  592. /** \ingroup libusb_desc
  593. * A structure representing the superspeed endpoint companion
  594. * descriptor. This descriptor is documented in section 9.6.7 of
  595. * the USB 3.0 specification. All multiple-byte fields are represented in
  596. * host-endian format.
  597. */
  598. struct libusb_ss_endpoint_companion_descriptor {
  599. /** Size of this descriptor (in bytes) */
  600. uint8_t bLength;
  601. /** Descriptor type. Will have value
  602. * \ref libusb_descriptor_type::LIBUSB_DT_SS_ENDPOINT_COMPANION in
  603. * this context. */
  604. uint8_t bDescriptorType;
  605. /** The maximum number of packets the endpoint can send or
  606. * receive as part of a burst. */
  607. uint8_t bMaxBurst;
  608. /** In bulk EP: bits 4:0 represents the maximum number of
  609. * streams the EP supports. In isochronous EP: bits 1:0
  610. * represents the Mult - a zero based value that determines
  611. * the maximum number of packets within a service interval */
  612. uint8_t bmAttributes;
  613. /** The total number of bytes this EP will transfer every
  614. * service interval. Valid only for periodic EPs. */
  615. uint16_t wBytesPerInterval;
  616. };
  617. /** \ingroup libusb_desc
  618. * A generic representation of a BOS Device Capability descriptor. It is
  619. * advised to check bDevCapabilityType and call the matching
  620. * libusb_get_*_descriptor function to get a structure fully matching the type.
  621. */
  622. struct libusb_bos_dev_capability_descriptor {
  623. /** Size of this descriptor (in bytes) */
  624. uint8_t bLength;
  625. /** Descriptor type. Will have value
  626. * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
  627. * LIBUSB_DT_DEVICE_CAPABILITY in this context. */
  628. uint8_t bDescriptorType;
  629. /** Device Capability type */
  630. uint8_t bDevCapabilityType;
  631. /** Device Capability data (bLength - 3 bytes) */
  632. uint8_t dev_capability_data[ZERO_SIZED_ARRAY];
  633. };
  634. /** \ingroup libusb_desc
  635. * A structure representing the Binary Device Object Store (BOS) descriptor.
  636. * This descriptor is documented in section 9.6.2 of the USB 3.0 specification.
  637. * All multiple-byte fields are represented in host-endian format.
  638. */
  639. struct libusb_bos_descriptor {
  640. /** Size of this descriptor (in bytes) */
  641. uint8_t bLength;
  642. /** Descriptor type. Will have value
  643. * \ref libusb_descriptor_type::LIBUSB_DT_BOS LIBUSB_DT_BOS
  644. * in this context. */
  645. uint8_t bDescriptorType;
  646. /** Length of this descriptor and all of its sub descriptors */
  647. uint16_t wTotalLength;
  648. /** The number of separate device capability descriptors in
  649. * the BOS */
  650. uint8_t bNumDeviceCaps;
  651. /** bNumDeviceCap Device Capability Descriptors */
  652. struct libusb_bos_dev_capability_descriptor *dev_capability[ZERO_SIZED_ARRAY];
  653. };
  654. /** \ingroup libusb_desc
  655. * A structure representing the USB 2.0 Extension descriptor
  656. * This descriptor is documented in section 9.6.2.1 of the USB 3.0 specification.
  657. * All multiple-byte fields are represented in host-endian format.
  658. */
  659. struct libusb_usb_2_0_extension_descriptor {
  660. /** Size of this descriptor (in bytes) */
  661. uint8_t bLength;
  662. /** Descriptor type. Will have value
  663. * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
  664. * LIBUSB_DT_DEVICE_CAPABILITY in this context. */
  665. uint8_t bDescriptorType;
  666. /** Capability type. Will have value
  667. * \ref libusb_capability_type::LIBUSB_BT_USB_2_0_EXTENSION
  668. * LIBUSB_BT_USB_2_0_EXTENSION in this context. */
  669. uint8_t bDevCapabilityType;
  670. /** Bitmap encoding of supported device level features.
  671. * A value of one in a bit location indicates a feature is
  672. * supported; a value of zero indicates it is not supported.
  673. * See \ref libusb_usb_2_0_extension_attributes. */
  674. uint32_t bmAttributes;
  675. };
  676. /** \ingroup libusb_desc
  677. * A structure representing the SuperSpeed USB Device Capability descriptor
  678. * This descriptor is documented in section 9.6.2.2 of the USB 3.0 specification.
  679. * All multiple-byte fields are represented in host-endian format.
  680. */
  681. struct libusb_ss_usb_device_capability_descriptor {
  682. /** Size of this descriptor (in bytes) */
  683. uint8_t bLength;
  684. /** Descriptor type. Will have value
  685. * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
  686. * LIBUSB_DT_DEVICE_CAPABILITY in this context. */
  687. uint8_t bDescriptorType;
  688. /** Capability type. Will have value
  689. * \ref libusb_capability_type::LIBUSB_BT_SS_USB_DEVICE_CAPABILITY
  690. * LIBUSB_BT_SS_USB_DEVICE_CAPABILITY in this context. */
  691. uint8_t bDevCapabilityType;
  692. /** Bitmap encoding of supported device level features.
  693. * A value of one in a bit location indicates a feature is
  694. * supported; a value of zero indicates it is not supported.
  695. * See \ref libusb_ss_usb_device_capability_attributes. */
  696. uint8_t bmAttributes;
  697. /** Bitmap encoding of the speed supported by this device when
  698. * operating in SuperSpeed mode. See \ref libusb_supported_speed. */
  699. uint16_t wSpeedSupported;
  700. /** The lowest speed at which all the functionality supported
  701. * by the device is available to the user. For example if the
  702. * device supports all its functionality when connected at
  703. * full speed and above then it sets this value to 1. */
  704. uint8_t bFunctionalitySupport;
  705. /** U1 Device Exit Latency. */
  706. uint8_t bU1DevExitLat;
  707. /** U2 Device Exit Latency. */
  708. uint16_t bU2DevExitLat;
  709. };
  710. /** \ingroup libusb_desc
  711. * A structure representing the Container ID descriptor.
  712. * This descriptor is documented in section 9.6.2.3 of the USB 3.0 specification.
  713. * All multiple-byte fields, except UUIDs, are represented in host-endian format.
  714. */
  715. struct libusb_container_id_descriptor {
  716. /** Size of this descriptor (in bytes) */
  717. uint8_t bLength;
  718. /** Descriptor type. Will have value
  719. * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
  720. * LIBUSB_DT_DEVICE_CAPABILITY in this context. */
  721. uint8_t bDescriptorType;
  722. /** Capability type. Will have value
  723. * \ref libusb_capability_type::LIBUSB_BT_CONTAINER_ID
  724. * LIBUSB_BT_CONTAINER_ID in this context. */
  725. uint8_t bDevCapabilityType;
  726. /** Reserved field */
  727. uint8_t bReserved;
  728. /** 128 bit UUID */
  729. uint8_t ContainerID[16];
  730. };
  731. /** \ingroup libusb_asyncio
  732. * Setup packet for control transfers. */
  733. #if defined(_MSC_VER) || defined(__WATCOMC__)
  734. #pragma pack(push, 1)
  735. #endif
  736. struct libusb_control_setup {
  737. /** Request type. Bits 0:4 determine recipient, see
  738. * \ref libusb_request_recipient. Bits 5:6 determine type, see
  739. * \ref libusb_request_type. Bit 7 determines data transfer direction, see
  740. * \ref libusb_endpoint_direction.
  741. */
  742. uint8_t bmRequestType;
  743. /** Request. If the type bits of bmRequestType are equal to
  744. * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD
  745. * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to
  746. * \ref libusb_standard_request. For other cases, use of this field is
  747. * application-specific. */
  748. uint8_t bRequest;
  749. /** Value. Varies according to request */
  750. uint16_t wValue;
  751. /** Index. Varies according to request, typically used to pass an index
  752. * or offset */
  753. uint16_t wIndex;
  754. /** Number of bytes to transfer */
  755. uint16_t wLength;
  756. } LIBUSB_PACKED;
  757. #if defined(_MSC_VER) || defined(__WATCOMC__)
  758. #pragma pack(pop)
  759. #endif
  760. #define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
  761. /* libusb */
  762. struct libusb_context;
  763. struct libusb_device;
  764. struct libusb_device_handle;
  765. /** \ingroup libusb_lib
  766. * Structure providing the version of the libusb runtime
  767. */
  768. struct libusb_version {
  769. /** Library major version. */
  770. const uint16_t major;
  771. /** Library minor version. */
  772. const uint16_t minor;
  773. /** Library micro version. */
  774. const uint16_t micro;
  775. /** Library nano version. */
  776. const uint16_t nano;
  777. /** Library release candidate suffix string, e.g. "-rc4". */
  778. const char *rc;
  779. /** For ABI compatibility only. */
  780. const char *describe;
  781. };
  782. /** \ingroup libusb_lib
  783. * Structure representing a libusb session. The concept of individual libusb
  784. * sessions allows for your program to use two libraries (or dynamically
  785. * load two modules) which both independently use libusb. This will prevent
  786. * interference between the individual libusb users - for example
  787. * libusb_set_option() will not affect the other user of the library, and
  788. * libusb_exit() will not destroy resources that the other user is still
  789. * using.
  790. *
  791. * Sessions are created by libusb_init() and destroyed through libusb_exit().
  792. * If your application is guaranteed to only ever include a single libusb
  793. * user (i.e. you), you do not have to worry about contexts: pass NULL in
  794. * every function call where a context is required, and the default context
  795. * will be used. Note that libusb_set_option(NULL, ...) is special, and adds
  796. * an option to a list of default options for new contexts.
  797. *
  798. * For more information, see \ref libusb_contexts.
  799. */
  800. typedef struct libusb_context libusb_context;
  801. /** \ingroup libusb_dev
  802. * Structure representing a USB device detected on the system. This is an
  803. * opaque type for which you are only ever provided with a pointer, usually
  804. * originating from libusb_get_device_list() or libusb_hotplug_register_callback().
  805. *
  806. * Certain operations can be performed on a device, but in order to do any
  807. * I/O you will have to first obtain a device handle using libusb_open().
  808. *
  809. * Devices are reference counted with libusb_ref_device() and
  810. * libusb_unref_device(), and are freed when the reference count reaches 0.
  811. * New devices presented by libusb_get_device_list() have a reference count of
  812. * 1, and libusb_free_device_list() can optionally decrease the reference count
  813. * on all devices in the list. libusb_open() adds another reference which is
  814. * later destroyed by libusb_close().
  815. */
  816. typedef struct libusb_device libusb_device;
  817. /** \ingroup libusb_dev
  818. * Structure representing a handle on a USB device. This is an opaque type for
  819. * which you are only ever provided with a pointer, usually originating from
  820. * libusb_open().
  821. *
  822. * A device handle is used to perform I/O and other operations. When finished
  823. * with a device handle, you should call libusb_close().
  824. */
  825. typedef struct libusb_device_handle libusb_device_handle;
  826. /** \ingroup libusb_dev
  827. * Speed codes. Indicates the speed at which the device is operating.
  828. */
  829. enum libusb_speed {
  830. /** The OS doesn't report or know the device speed. */
  831. LIBUSB_SPEED_UNKNOWN = 0,
  832. /** The device is operating at low speed (1.5MBit/s). */
  833. LIBUSB_SPEED_LOW = 1,
  834. /** The device is operating at full speed (12MBit/s). */
  835. LIBUSB_SPEED_FULL = 2,
  836. /** The device is operating at high speed (480MBit/s). */
  837. LIBUSB_SPEED_HIGH = 3,
  838. /** The device is operating at super speed (5000MBit/s). */
  839. LIBUSB_SPEED_SUPER = 4,
  840. /** The device is operating at super speed plus (10000MBit/s). */
  841. LIBUSB_SPEED_SUPER_PLUS = 5
  842. };
  843. /** \ingroup libusb_misc
  844. * Error codes. Most libusb functions return 0 on success or one of these
  845. * codes on failure.
  846. * You can call libusb_error_name() to retrieve a string representation of an
  847. * error code or libusb_strerror() to get an end-user suitable description of
  848. * an error code.
  849. */
  850. enum libusb_error {
  851. /** Success (no error) */
  852. LIBUSB_SUCCESS = 0,
  853. /** Input/output error */
  854. LIBUSB_ERROR_IO = -1,
  855. /** Invalid parameter */
  856. LIBUSB_ERROR_INVALID_PARAM = -2,
  857. /** Access denied (insufficient permissions) */
  858. LIBUSB_ERROR_ACCESS = -3,
  859. /** No such device (it may have been disconnected) */
  860. LIBUSB_ERROR_NO_DEVICE = -4,
  861. /** Entity not found */
  862. LIBUSB_ERROR_NOT_FOUND = -5,
  863. /** Resource busy */
  864. LIBUSB_ERROR_BUSY = -6,
  865. /** Operation timed out */
  866. LIBUSB_ERROR_TIMEOUT = -7,
  867. /** Overflow */
  868. LIBUSB_ERROR_OVERFLOW = -8,
  869. /** Pipe error */
  870. LIBUSB_ERROR_PIPE = -9,
  871. /** System call interrupted (perhaps due to signal) */
  872. LIBUSB_ERROR_INTERRUPTED = -10,
  873. /** Insufficient memory */
  874. LIBUSB_ERROR_NO_MEM = -11,
  875. /** Operation not supported or unimplemented on this platform */
  876. LIBUSB_ERROR_NOT_SUPPORTED = -12,
  877. /* NB: Remember to update LIBUSB_ERROR_COUNT below as well as the
  878. message strings in strerror.c when adding new error codes here. */
  879. /** Other error */
  880. LIBUSB_ERROR_OTHER = -99
  881. };
  882. /* Total number of error codes in enum libusb_error */
  883. #define LIBUSB_ERROR_COUNT 14
  884. /** \ingroup libusb_asyncio
  885. * Transfer type */
  886. enum libusb_transfer_type {
  887. /** Control transfer */
  888. LIBUSB_TRANSFER_TYPE_CONTROL = 0U,
  889. /** Isochronous transfer */
  890. LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1U,
  891. /** Bulk transfer */
  892. LIBUSB_TRANSFER_TYPE_BULK = 2U,
  893. /** Interrupt transfer */
  894. LIBUSB_TRANSFER_TYPE_INTERRUPT = 3U,
  895. /** Bulk stream transfer */
  896. LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4U
  897. };
  898. /** \ingroup libusb_asyncio
  899. * Transfer status codes */
  900. enum libusb_transfer_status {
  901. /** Transfer completed without error. Note that this does not indicate
  902. * that the entire amount of requested data was transferred. */
  903. LIBUSB_TRANSFER_COMPLETED,
  904. /** Transfer failed */
  905. LIBUSB_TRANSFER_ERROR,
  906. /** Transfer timed out */
  907. LIBUSB_TRANSFER_TIMED_OUT,
  908. /** Transfer was cancelled */
  909. LIBUSB_TRANSFER_CANCELLED,
  910. /** For bulk/interrupt endpoints: halt condition detected (endpoint
  911. * stalled). For control endpoints: control request not supported. */
  912. LIBUSB_TRANSFER_STALL,
  913. /** Device was disconnected */
  914. LIBUSB_TRANSFER_NO_DEVICE,
  915. /** Device sent more data than requested */
  916. LIBUSB_TRANSFER_OVERFLOW
  917. /* NB! Remember to update libusb_error_name()
  918. when adding new status codes here. */
  919. };
  920. /** \ingroup libusb_asyncio
  921. * libusb_transfer.flags values */
  922. enum libusb_transfer_flags {
  923. /** Report short frames as errors */
  924. LIBUSB_TRANSFER_SHORT_NOT_OK = (1U << 0),
  925. /** Automatically free() transfer buffer during libusb_free_transfer().
  926. * Note that buffers allocated with libusb_dev_mem_alloc() should not
  927. * be attempted freed in this way, since free() is not an appropriate
  928. * way to release such memory. */
  929. LIBUSB_TRANSFER_FREE_BUFFER = (1U << 1),
  930. /** Automatically call libusb_free_transfer() after callback returns.
  931. * If this flag is set, it is illegal to call libusb_free_transfer()
  932. * from your transfer callback, as this will result in a double-free
  933. * when this flag is acted upon. */
  934. LIBUSB_TRANSFER_FREE_TRANSFER = (1U << 2),
  935. /** Terminate transfers that are a multiple of the endpoint's
  936. * wMaxPacketSize with an extra zero length packet. This is useful
  937. * when a device protocol mandates that each logical request is
  938. * terminated by an incomplete packet (i.e. the logical requests are
  939. * not separated by other means).
  940. *
  941. * This flag only affects host-to-device transfers to bulk and interrupt
  942. * endpoints. In other situations, it is ignored.
  943. *
  944. * This flag only affects transfers with a length that is a multiple of
  945. * the endpoint's wMaxPacketSize. On transfers of other lengths, this
  946. * flag has no effect. Therefore, if you are working with a device that
  947. * needs a ZLP whenever the end of the logical request falls on a packet
  948. * boundary, then it is sensible to set this flag on <em>every</em>
  949. * transfer (you do not have to worry about only setting it on transfers
  950. * that end on the boundary).
  951. *
  952. * This flag is currently only supported on Linux.
  953. * On other systems, libusb_submit_transfer() will return
  954. * LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag is set.
  955. *
  956. * Available since libusb-1.0.9.
  957. */
  958. LIBUSB_TRANSFER_ADD_ZERO_PACKET = (1U << 3)
  959. };
  960. /** \ingroup libusb_asyncio
  961. * Isochronous packet descriptor. */
  962. struct libusb_iso_packet_descriptor {
  963. /** Length of data to request in this packet */
  964. unsigned int length;
  965. /** Amount of data that was actually transferred */
  966. unsigned int actual_length;
  967. /** Status code for this packet */
  968. enum libusb_transfer_status status;
  969. };
  970. struct libusb_transfer;
  971. /** \ingroup libusb_asyncio
  972. * Asynchronous transfer callback function type. When submitting asynchronous
  973. * transfers, you pass a pointer to a callback function of this type via the
  974. * \ref libusb_transfer::callback "callback" member of the libusb_transfer
  975. * structure. libusb will call this function later, when the transfer has
  976. * completed or failed. See \ref libusb_asyncio for more information.
  977. * \param transfer The libusb_transfer struct the callback function is being
  978. * notified about.
  979. */
  980. typedef void (LIBUSB_CALL *libusb_transfer_cb_fn)(struct libusb_transfer *transfer);
  981. /** \ingroup libusb_asyncio
  982. * The generic USB transfer structure. The user populates this structure and
  983. * then submits it in order to request a transfer. After the transfer has
  984. * completed, the library populates the transfer with the results and passes
  985. * it back to the user.
  986. */
  987. struct libusb_transfer {
  988. /** Handle of the device that this transfer will be submitted to */
  989. libusb_device_handle *dev_handle;
  990. /** A bitwise OR combination of \ref libusb_transfer_flags. */
  991. uint8_t flags;
  992. /** Address of the endpoint where this transfer will be sent. */
  993. unsigned char endpoint;
  994. /** Type of the transfer from \ref libusb_transfer_type */
  995. unsigned char type;
  996. /** Timeout for this transfer in milliseconds. A value of 0 indicates no
  997. * timeout. */
  998. unsigned int timeout;
  999. /** The status of the transfer. Read-only, and only for use within
  1000. * transfer callback function.
  1001. *
  1002. * If this is an isochronous transfer, this field may read COMPLETED even
  1003. * if there were errors in the frames. Use the
  1004. * \ref libusb_iso_packet_descriptor::status "status" field in each packet
  1005. * to determine if errors occurred. */
  1006. enum libusb_transfer_status status;
  1007. /** Length of the data buffer. Must be non-negative. */
  1008. int length;
  1009. /** Actual length of data that was transferred. Read-only, and only for
  1010. * use within transfer callback function. Not valid for isochronous
  1011. * endpoint transfers. */
  1012. int actual_length;
  1013. /** Callback function. This will be invoked when the transfer completes,
  1014. * fails, or is cancelled. */
  1015. libusb_transfer_cb_fn callback;
  1016. /** User context data. Useful for associating specific data to a transfer
  1017. * that can be accessed from within the callback function.
  1018. *
  1019. * This field may be set manually or is taken as the `user_data` parameter
  1020. * of the following functions:
  1021. * - libusb_fill_bulk_transfer()
  1022. * - libusb_fill_bulk_stream_transfer()
  1023. * - libusb_fill_control_transfer()
  1024. * - libusb_fill_interrupt_transfer()
  1025. * - libusb_fill_iso_transfer() */
  1026. void *user_data;
  1027. /** Data buffer */
  1028. unsigned char *buffer;
  1029. /** Number of isochronous packets. Only used for I/O with isochronous
  1030. * endpoints. Must be non-negative. */
  1031. int num_iso_packets;
  1032. /** Isochronous packet descriptors, for isochronous transfers only. */
  1033. struct libusb_iso_packet_descriptor iso_packet_desc[ZERO_SIZED_ARRAY];
  1034. };
  1035. /** \ingroup libusb_misc
  1036. * Capabilities supported by an instance of libusb on the current running
  1037. * platform. Test if the loaded library supports a given capability by calling
  1038. * \ref libusb_has_capability().
  1039. */
  1040. enum libusb_capability {
  1041. /** The libusb_has_capability() API is available. */
  1042. LIBUSB_CAP_HAS_CAPABILITY = 0x0000U,
  1043. /** Hotplug support is available on this platform. */
  1044. LIBUSB_CAP_HAS_HOTPLUG = 0x0001U,
  1045. /** The library can access HID devices without requiring user intervention.
  1046. * Note that before being able to actually access an HID device, you may
  1047. * still have to call additional libusb functions such as
  1048. * \ref libusb_detach_kernel_driver(). */
  1049. LIBUSB_CAP_HAS_HID_ACCESS = 0x0100U,
  1050. /** The library supports detaching of the default USB driver, using
  1051. * \ref libusb_detach_kernel_driver(), if one is set by the OS kernel */
  1052. LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101U
  1053. };
  1054. /** \ingroup libusb_lib
  1055. * Log message levels.
  1056. */
  1057. enum libusb_log_level {
  1058. /** (0) : No messages ever emitted by the library (default) */
  1059. LIBUSB_LOG_LEVEL_NONE = 0,
  1060. /** (1) : Error messages are emitted */
  1061. LIBUSB_LOG_LEVEL_ERROR = 1,
  1062. /** (2) : Warning and error messages are emitted */
  1063. LIBUSB_LOG_LEVEL_WARNING = 2,
  1064. /** (3) : Informational, warning and error messages are emitted */
  1065. LIBUSB_LOG_LEVEL_INFO = 3,
  1066. /** (4) : All messages are emitted */
  1067. LIBUSB_LOG_LEVEL_DEBUG = 4
  1068. };
  1069. /** \ingroup libusb_lib
  1070. * Log callback mode.
  1071. *
  1072. * Since version 1.0.23, \ref LIBUSB_API_VERSION >= 0x01000107
  1073. *
  1074. * \see libusb_set_log_cb()
  1075. */
  1076. enum libusb_log_cb_mode {
  1077. /** Callback function handling all log messages. */
  1078. LIBUSB_LOG_CB_GLOBAL = (1 << 0),
  1079. /** Callback function handling context related log messages. */
  1080. LIBUSB_LOG_CB_CONTEXT = (1 << 1)
  1081. };
  1082. /** \ingroup libusb_lib
  1083. * Callback function for handling log messages.
  1084. * \param ctx the context which is related to the log message, or NULL if it
  1085. * is a global log message
  1086. * \param level the log level, see \ref libusb_log_level for a description
  1087. * \param str the log message
  1088. *
  1089. * Since version 1.0.23, \ref LIBUSB_API_VERSION >= 0x01000107
  1090. *
  1091. * \see libusb_set_log_cb()
  1092. */
  1093. typedef void (LIBUSB_CALL *libusb_log_cb)(libusb_context *ctx,
  1094. enum libusb_log_level level, const char *str);
  1095. int LIBUSB_CALL libusb_init(libusb_context **ctx);
  1096. void LIBUSB_CALL libusb_exit(libusb_context *ctx);
  1097. LIBUSB_DEPRECATED_FOR(libusb_set_option)
  1098. void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
  1099. void LIBUSB_CALL libusb_set_log_cb(libusb_context *ctx, libusb_log_cb cb, int mode);
  1100. const struct libusb_version * LIBUSB_CALL libusb_get_version(void);
  1101. int LIBUSB_CALL libusb_has_capability(uint32_t capability);
  1102. const char * LIBUSB_CALL libusb_error_name(int errcode);
  1103. int LIBUSB_CALL libusb_setlocale(const char *locale);
  1104. const char * LIBUSB_CALL libusb_strerror(int errcode);
  1105. ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
  1106. libusb_device ***list);
  1107. void LIBUSB_CALL libusb_free_device_list(libusb_device **list,
  1108. int unref_devices);
  1109. libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev);
  1110. void LIBUSB_CALL libusb_unref_device(libusb_device *dev);
  1111. int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
  1112. int *config);
  1113. int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,
  1114. struct libusb_device_descriptor *desc);
  1115. int LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev,
  1116. struct libusb_config_descriptor **config);
  1117. int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev,
  1118. uint8_t config_index, struct libusb_config_descriptor **config);
  1119. int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,
  1120. uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
  1121. void LIBUSB_CALL libusb_free_config_descriptor(
  1122. struct libusb_config_descriptor *config);
  1123. int LIBUSB_CALL libusb_get_ss_endpoint_companion_descriptor(
  1124. libusb_context *ctx,
  1125. const struct libusb_endpoint_descriptor *endpoint,
  1126. struct libusb_ss_endpoint_companion_descriptor **ep_comp);
  1127. void LIBUSB_CALL libusb_free_ss_endpoint_companion_descriptor(
  1128. struct libusb_ss_endpoint_companion_descriptor *ep_comp);
  1129. int LIBUSB_CALL libusb_get_bos_descriptor(libusb_device_handle *dev_handle,
  1130. struct libusb_bos_descriptor **bos);
  1131. void LIBUSB_CALL libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos);
  1132. int LIBUSB_CALL libusb_get_usb_2_0_extension_descriptor(
  1133. libusb_context *ctx,
  1134. struct libusb_bos_dev_capability_descriptor *dev_cap,
  1135. struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension);
  1136. void LIBUSB_CALL libusb_free_usb_2_0_extension_descriptor(
  1137. struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension);
  1138. int LIBUSB_CALL libusb_get_ss_usb_device_capability_descriptor(
  1139. libusb_context *ctx,
  1140. struct libusb_bos_dev_capability_descriptor *dev_cap,
  1141. struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_cap);
  1142. void LIBUSB_CALL libusb_free_ss_usb_device_capability_descriptor(
  1143. struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_cap);
  1144. int LIBUSB_CALL libusb_get_container_id_descriptor(libusb_context *ctx,
  1145. struct libusb_bos_dev_capability_descriptor *dev_cap,
  1146. struct libusb_container_id_descriptor **container_id);
  1147. void LIBUSB_CALL libusb_free_container_id_descriptor(
  1148. struct libusb_container_id_descriptor *container_id);
  1149. uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
  1150. uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev);
  1151. int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t *port_numbers, int port_numbers_len);
  1152. LIBUSB_DEPRECATED_FOR(libusb_get_port_numbers)
  1153. int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t *path, uint8_t path_length);
  1154. libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev);
  1155. uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
  1156. int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
  1157. int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
  1158. unsigned char endpoint);
  1159. int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
  1160. unsigned char endpoint);
  1161. int LIBUSB_CALL libusb_wrap_sys_device(libusb_context *ctx, intptr_t sys_dev, libusb_device_handle **dev_handle);
  1162. int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **dev_handle);
  1163. void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle);
  1164. libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle);
  1165. int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev_handle,
  1166. int configuration);
  1167. int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev_handle,
  1168. int interface_number);
  1169. int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev_handle,
  1170. int interface_number);
  1171. libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid(
  1172. libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
  1173. int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev_handle,
  1174. int interface_number, int alternate_setting);
  1175. int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev_handle,
  1176. unsigned char endpoint);
  1177. int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev_handle);
  1178. int LIBUSB_CALL libusb_alloc_streams(libusb_device_handle *dev_handle,
  1179. uint32_t num_streams, unsigned char *endpoints, int num_endpoints);
  1180. int LIBUSB_CALL libusb_free_streams(libusb_device_handle *dev_handle,
  1181. unsigned char *endpoints, int num_endpoints);
  1182. unsigned char * LIBUSB_CALL libusb_dev_mem_alloc(libusb_device_handle *dev_handle,
  1183. size_t length);
  1184. int LIBUSB_CALL libusb_dev_mem_free(libusb_device_handle *dev_handle,
  1185. unsigned char *buffer, size_t length);
  1186. int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev_handle,
  1187. int interface_number);
  1188. int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev_handle,
  1189. int interface_number);
  1190. int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev_handle,
  1191. int interface_number);
  1192. int LIBUSB_CALL libusb_set_auto_detach_kernel_driver(
  1193. libusb_device_handle *dev_handle, int enable);
  1194. /* async I/O */
  1195. /** \ingroup libusb_asyncio
  1196. * Get the data section of a control transfer. This convenience function is here
  1197. * to remind you that the data does not start until 8 bytes into the actual
  1198. * buffer, as the setup packet comes first.
  1199. *
  1200. * Calling this function only makes sense from a transfer callback function,
  1201. * or situations where you have already allocated a suitably sized buffer at
  1202. * transfer->buffer.
  1203. *
  1204. * \param transfer a transfer
  1205. * \returns pointer to the first byte of the data section
  1206. */
  1207. static inline unsigned char *libusb_control_transfer_get_data(
  1208. struct libusb_transfer *transfer)
  1209. {
  1210. return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
  1211. }
  1212. /** \ingroup libusb_asyncio
  1213. * Get the control setup packet of a control transfer. This convenience
  1214. * function is here to remind you that the control setup occupies the first
  1215. * 8 bytes of the transfer data buffer.
  1216. *
  1217. * Calling this function only makes sense from a transfer callback function,
  1218. * or situations where you have already allocated a suitably sized buffer at
  1219. * transfer->buffer.
  1220. *
  1221. * \param transfer a transfer
  1222. * \returns a casted pointer to the start of the transfer data buffer
  1223. */
  1224. static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
  1225. struct libusb_transfer *transfer)
  1226. {
  1227. return (struct libusb_control_setup *)(void *)transfer->buffer;
  1228. }
  1229. /** \ingroup libusb_asyncio
  1230. * Helper function to populate the setup packet (first 8 bytes of the data
  1231. * buffer) for a control transfer. The wIndex, wValue and wLength values should
  1232. * be given in host-endian byte order.
  1233. *
  1234. * \param buffer buffer to output the setup packet into
  1235. * This pointer must be aligned to at least 2 bytes boundary.
  1236. * \param bmRequestType see the
  1237. * \ref libusb_control_setup::bmRequestType "bmRequestType" field of
  1238. * \ref libusb_control_setup
  1239. * \param bRequest see the
  1240. * \ref libusb_control_setup::bRequest "bRequest" field of
  1241. * \ref libusb_control_setup
  1242. * \param wValue see the
  1243. * \ref libusb_control_setup::wValue "wValue" field of
  1244. * \ref libusb_control_setup
  1245. * \param wIndex see the
  1246. * \ref libusb_control_setup::wIndex "wIndex" field of
  1247. * \ref libusb_control_setup
  1248. * \param wLength see the
  1249. * \ref libusb_control_setup::wLength "wLength" field of
  1250. * \ref libusb_control_setup
  1251. */
  1252. static inline void libusb_fill_control_setup(unsigned char *buffer,
  1253. uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
  1254. uint16_t wLength)
  1255. {
  1256. struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *)buffer;
  1257. setup->bmRequestType = bmRequestType;
  1258. setup->bRequest = bRequest;
  1259. setup->wValue = libusb_cpu_to_le16(wValue);
  1260. setup->wIndex = libusb_cpu_to_le16(wIndex);
  1261. setup->wLength = libusb_cpu_to_le16(wLength);
  1262. }
  1263. struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets);
  1264. int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer);
  1265. int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer);
  1266. void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer);
  1267. void LIBUSB_CALL libusb_transfer_set_stream_id(
  1268. struct libusb_transfer *transfer, uint32_t stream_id);
  1269. uint32_t LIBUSB_CALL libusb_transfer_get_stream_id(
  1270. struct libusb_transfer *transfer);
  1271. /** \ingroup libusb_asyncio
  1272. * Helper function to populate the required \ref libusb_transfer fields
  1273. * for a control transfer.
  1274. *
  1275. * If you pass a transfer buffer to this function, the first 8 bytes will
  1276. * be interpreted as a control setup packet, and the wLength field will be
  1277. * used to automatically populate the \ref libusb_transfer::length "length"
  1278. * field of the transfer. Therefore the recommended approach is:
  1279. * -# Allocate a suitably sized data buffer (including space for control setup)
  1280. * -# Call libusb_fill_control_setup()
  1281. * -# If this is a host-to-device transfer with a data stage, put the data
  1282. * in place after the setup packet
  1283. * -# Call this function
  1284. * -# Call libusb_submit_transfer()
  1285. *
  1286. * It is also legal to pass a NULL buffer to this function, in which case this
  1287. * function will not attempt to populate the length field. Remember that you
  1288. * must then populate the buffer and length fields later.
  1289. *
  1290. * \param transfer the transfer to populate
  1291. * \param dev_handle handle of the device that will handle the transfer
  1292. * \param buffer data buffer. If provided, this function will interpret the
  1293. * first 8 bytes as a setup packet and infer the transfer length from that.
  1294. * This pointer must be aligned to at least 2 bytes boundary.
  1295. * \param callback callback function to be invoked on transfer completion
  1296. * \param user_data user data to pass to callback function
  1297. * \param timeout timeout for the transfer in milliseconds
  1298. */
  1299. static inline void libusb_fill_control_transfer(
  1300. struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
  1301. unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
  1302. unsigned int timeout)
  1303. {
  1304. struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *)buffer;
  1305. transfer->dev_handle = dev_handle;
  1306. transfer->endpoint = 0;
  1307. transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;
  1308. transfer->timeout = timeout;
  1309. transfer->buffer = buffer;
  1310. if (setup)
  1311. transfer->length = (int) (LIBUSB_CONTROL_SETUP_SIZE
  1312. + libusb_le16_to_cpu(setup->wLength));
  1313. transfer->user_data = user_data;
  1314. transfer->callback = callback;
  1315. }
  1316. /** \ingroup libusb_asyncio
  1317. * Helper function to populate the required \ref libusb_transfer fields
  1318. * for a bulk transfer.
  1319. *
  1320. * \param transfer the transfer to populate
  1321. * \param dev_handle handle of the device that will handle the transfer
  1322. * \param endpoint address of the endpoint where this transfer will be sent
  1323. * \param buffer data buffer
  1324. * \param length length of data buffer
  1325. * \param callback callback function to be invoked on transfer completion
  1326. * \param user_data user data to pass to callback function
  1327. * \param timeout timeout for the transfer in milliseconds
  1328. */
  1329. static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
  1330. libusb_device_handle *dev_handle, unsigned char endpoint,
  1331. unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
  1332. void *user_data, unsigned int timeout)
  1333. {
  1334. transfer->dev_handle = dev_handle;
  1335. transfer->endpoint = endpoint;
  1336. transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
  1337. transfer->timeout = timeout;
  1338. transfer->buffer = buffer;
  1339. transfer->length = length;
  1340. transfer->user_data = user_data;
  1341. transfer->callback = callback;
  1342. }
  1343. /** \ingroup libusb_asyncio
  1344. * Helper function to populate the required \ref libusb_transfer fields
  1345. * for a bulk transfer using bulk streams.
  1346. *
  1347. * Since version 1.0.19, \ref LIBUSB_API_VERSION >= 0x01000103
  1348. *
  1349. * \param transfer the transfer to populate
  1350. * \param dev_handle handle of the device that will handle the transfer
  1351. * \param endpoint address of the endpoint where this transfer will be sent
  1352. * \param stream_id bulk stream id for this transfer
  1353. * \param buffer data buffer
  1354. * \param length length of data buffer
  1355. * \param callback callback function to be invoked on transfer completion
  1356. * \param user_data user data to pass to callback function
  1357. * \param timeout timeout for the transfer in milliseconds
  1358. */
  1359. static inline void libusb_fill_bulk_stream_transfer(
  1360. struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
  1361. unsigned char endpoint, uint32_t stream_id,
  1362. unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
  1363. void *user_data, unsigned int timeout)
  1364. {
  1365. libusb_fill_bulk_transfer(transfer, dev_handle, endpoint, buffer,
  1366. length, callback, user_data, timeout);
  1367. transfer->type = LIBUSB_TRANSFER_TYPE_BULK_STREAM;
  1368. libusb_transfer_set_stream_id(transfer, stream_id);
  1369. }
  1370. /** \ingroup libusb_asyncio
  1371. * Helper function to populate the required \ref libusb_transfer fields
  1372. * for an interrupt transfer.
  1373. *
  1374. * \param transfer the transfer to populate
  1375. * \param dev_handle handle of the device that will handle the transfer
  1376. * \param endpoint address of the endpoint where this transfer will be sent
  1377. * \param buffer data buffer
  1378. * \param length length of data buffer
  1379. * \param callback callback function to be invoked on transfer completion
  1380. * \param user_data user data to pass to callback function
  1381. * \param timeout timeout for the transfer in milliseconds
  1382. */
  1383. static inline void libusb_fill_interrupt_transfer(
  1384. struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
  1385. unsigned char endpoint, unsigned char *buffer, int length,
  1386. libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
  1387. {
  1388. transfer->dev_handle = dev_handle;
  1389. transfer->endpoint = endpoint;
  1390. transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;
  1391. transfer->timeout = timeout;
  1392. transfer->buffer = buffer;
  1393. transfer->length = length;
  1394. transfer->user_data = user_data;
  1395. transfer->callback = callback;
  1396. }
  1397. /** \ingroup libusb_asyncio
  1398. * Helper function to populate the required \ref libusb_transfer fields
  1399. * for an isochronous transfer.
  1400. *
  1401. * \param transfer the transfer to populate
  1402. * \param dev_handle handle of the device that will handle the transfer
  1403. * \param endpoint address of the endpoint where this transfer will be sent
  1404. * \param buffer data buffer
  1405. * \param length length of data buffer
  1406. * \param num_iso_packets the number of isochronous packets
  1407. * \param callback callback function to be invoked on transfer completion
  1408. * \param user_data user data to pass to callback function
  1409. * \param timeout timeout for the transfer in milliseconds
  1410. */
  1411. static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,
  1412. libusb_device_handle *dev_handle, unsigned char endpoint,
  1413. unsigned char *buffer, int length, int num_iso_packets,
  1414. libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
  1415. {
  1416. transfer->dev_handle = dev_handle;
  1417. transfer->endpoint = endpoint;
  1418. transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
  1419. transfer->timeout = timeout;
  1420. transfer->buffer = buffer;
  1421. transfer->length = length;
  1422. transfer->num_iso_packets = num_iso_packets;
  1423. transfer->user_data = user_data;
  1424. transfer->callback = callback;
  1425. }
  1426. /** \ingroup libusb_asyncio
  1427. * Convenience function to set the length of all packets in an isochronous
  1428. * transfer, based on the num_iso_packets field in the transfer structure.
  1429. *
  1430. * \param transfer a transfer
  1431. * \param length the length to set in each isochronous packet descriptor
  1432. * \see libusb_get_max_packet_size()
  1433. */
  1434. static inline void libusb_set_iso_packet_lengths(
  1435. struct libusb_transfer *transfer, unsigned int length)
  1436. {
  1437. int i;
  1438. for (i = 0; i < transfer->num_iso_packets; i++)
  1439. transfer->iso_packet_desc[i].length = length;
  1440. }
  1441. /** \ingroup libusb_asyncio
  1442. * Convenience function to locate the position of an isochronous packet
  1443. * within the buffer of an isochronous transfer.
  1444. *
  1445. * This is a thorough function which loops through all preceding packets,
  1446. * accumulating their lengths to find the position of the specified packet.
  1447. * Typically you will assign equal lengths to each packet in the transfer,
  1448. * and hence the above method is sub-optimal. You may wish to use
  1449. * libusb_get_iso_packet_buffer_simple() instead.
  1450. *
  1451. * \param transfer a transfer
  1452. * \param packet the packet to return the address of
  1453. * \returns the base address of the packet buffer inside the transfer buffer,
  1454. * or NULL if the packet does not exist.
  1455. * \see libusb_get_iso_packet_buffer_simple()
  1456. */
  1457. static inline unsigned char *libusb_get_iso_packet_buffer(
  1458. struct libusb_transfer *transfer, unsigned int packet)
  1459. {
  1460. int i;
  1461. size_t offset = 0;
  1462. int _packet;
  1463. /* oops..slight bug in the API. packet is an unsigned int, but we use
  1464. * signed integers almost everywhere else. range-check and convert to
  1465. * signed to avoid compiler warnings. FIXME for libusb-2. */
  1466. if (packet > INT_MAX)
  1467. return NULL;
  1468. _packet = (int) packet;
  1469. if (_packet >= transfer->num_iso_packets)
  1470. return NULL;
  1471. for (i = 0; i < _packet; i++)
  1472. offset += transfer->iso_packet_desc[i].length;
  1473. return transfer->buffer + offset;
  1474. }
  1475. /** \ingroup libusb_asyncio
  1476. * Convenience function to locate the position of an isochronous packet
  1477. * within the buffer of an isochronous transfer, for transfers where each
  1478. * packet is of identical size.
  1479. *
  1480. * This function relies on the assumption that every packet within the transfer
  1481. * is of identical size to the first packet. Calculating the location of
  1482. * the packet buffer is then just a simple calculation:
  1483. * <tt>buffer + (packet_size * packet)</tt>
  1484. *
  1485. * Do not use this function on transfers other than those that have identical
  1486. * packet lengths for each packet.
  1487. *
  1488. * \param transfer a transfer
  1489. * \param packet the packet to return the address of
  1490. * \returns the base address of the packet buffer inside the transfer buffer,
  1491. * or NULL if the packet does not exist.
  1492. * \see libusb_get_iso_packet_buffer()
  1493. */
  1494. static inline unsigned char *libusb_get_iso_packet_buffer_simple(
  1495. struct libusb_transfer *transfer, unsigned int packet)
  1496. {
  1497. int _packet;
  1498. /* oops..slight bug in the API. packet is an unsigned int, but we use
  1499. * signed integers almost everywhere else. range-check and convert to
  1500. * signed to avoid compiler warnings. FIXME for libusb-2. */
  1501. if (packet > INT_MAX)
  1502. return NULL;
  1503. _packet = (int) packet;
  1504. if (_packet >= transfer->num_iso_packets)
  1505. return NULL;
  1506. return transfer->buffer + ((int) transfer->iso_packet_desc[0].length * _packet);
  1507. }
  1508. /* sync I/O */
  1509. int LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle,
  1510. uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
  1511. unsigned char *data, uint16_t wLength, unsigned int timeout);
  1512. int LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle,
  1513. unsigned char endpoint, unsigned char *data, int length,
  1514. int *actual_length, unsigned int timeout);
  1515. int LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle,
  1516. unsigned char endpoint, unsigned char *data, int length,
  1517. int *actual_length, unsigned int timeout);
  1518. /** \ingroup libusb_desc
  1519. * Retrieve a descriptor from the default control pipe.
  1520. * This is a convenience function which formulates the appropriate control
  1521. * message to retrieve the descriptor.
  1522. *
  1523. * \param dev_handle a device handle
  1524. * \param desc_type the descriptor type, see \ref libusb_descriptor_type
  1525. * \param desc_index the index of the descriptor to retrieve
  1526. * \param data output buffer for descriptor
  1527. * \param length size of data buffer
  1528. * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
  1529. */
  1530. static inline int libusb_get_descriptor(libusb_device_handle *dev_handle,
  1531. uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length)
  1532. {
  1533. return libusb_control_transfer(dev_handle, LIBUSB_ENDPOINT_IN,
  1534. LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t) ((desc_type << 8) | desc_index),
  1535. 0, data, (uint16_t) length, 1000);
  1536. }
  1537. /** \ingroup libusb_desc
  1538. * Retrieve a descriptor from a device.
  1539. * This is a convenience function which formulates the appropriate control
  1540. * message to retrieve the descriptor. The string returned is Unicode, as
  1541. * detailed in the USB specifications.
  1542. *
  1543. * \param dev_handle a device handle
  1544. * \param desc_index the index of the descriptor to retrieve
  1545. * \param langid the language ID for the string descriptor
  1546. * \param data output buffer for descriptor
  1547. * \param length size of data buffer
  1548. * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
  1549. * \see libusb_get_string_descriptor_ascii()
  1550. */
  1551. static inline int libusb_get_string_descriptor(libusb_device_handle *dev_handle,
  1552. uint8_t desc_index, uint16_t langid, unsigned char *data, int length)
  1553. {
  1554. return libusb_control_transfer(dev_handle, LIBUSB_ENDPOINT_IN,
  1555. LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t)((LIBUSB_DT_STRING << 8) | desc_index),
  1556. langid, data, (uint16_t) length, 1000);
  1557. }
  1558. int LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev_handle,
  1559. uint8_t desc_index, unsigned char *data, int length);
  1560. /* polling and timeouts */
  1561. int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx);
  1562. void LIBUSB_CALL libusb_lock_events(libusb_context *ctx);
  1563. void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx);
  1564. int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx);
  1565. int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx);
  1566. void LIBUSB_CALL libusb_interrupt_event_handler(libusb_context *ctx);
  1567. void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx);
  1568. void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx);
  1569. int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);
  1570. int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,
  1571. struct timeval *tv);
  1572. int LIBUSB_CALL libusb_handle_events_timeout_completed(libusb_context *ctx,
  1573. struct timeval *tv, int *completed);
  1574. int LIBUSB_CALL libusb_handle_events(libusb_context *ctx);
  1575. int LIBUSB_CALL libusb_handle_events_completed(libusb_context *ctx, int *completed);
  1576. int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
  1577. struct timeval *tv);
  1578. int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx);
  1579. int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
  1580. struct timeval *tv);
  1581. /** \ingroup libusb_poll
  1582. * File descriptor for polling
  1583. */
  1584. struct libusb_pollfd {
  1585. /** Numeric file descriptor */
  1586. int fd;
  1587. /** Event flags to poll for from <poll.h>. POLLIN indicates that you
  1588. * should monitor this file descriptor for becoming ready to read from,
  1589. * and POLLOUT indicates that you should monitor this file descriptor for
  1590. * nonblocking write readiness. */
  1591. short events;
  1592. };
  1593. /** \ingroup libusb_poll
  1594. * Callback function, invoked when a new file descriptor should be added
  1595. * to the set of file descriptors monitored for events.
  1596. * \param fd the new file descriptor
  1597. * \param events events to monitor for, see \ref libusb_pollfd for a
  1598. * description
  1599. * \param user_data User data pointer specified in
  1600. * libusb_set_pollfd_notifiers() call
  1601. * \see libusb_set_pollfd_notifiers()
  1602. */
  1603. typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events,
  1604. void *user_data);
  1605. /** \ingroup libusb_poll
  1606. * Callback function, invoked when a file descriptor should be removed from
  1607. * the set of file descriptors being monitored for events. After returning
  1608. * from this callback, do not use that file descriptor again.
  1609. * \param fd the file descriptor to stop monitoring
  1610. * \param user_data User data pointer specified in
  1611. * libusb_set_pollfd_notifiers() call
  1612. * \see libusb_set_pollfd_notifiers()
  1613. */
  1614. typedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(int fd, void *user_data);
  1615. const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(
  1616. libusb_context *ctx);
  1617. void LIBUSB_CALL libusb_free_pollfds(const struct libusb_pollfd **pollfds);
  1618. void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
  1619. libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
  1620. void *user_data);
  1621. /** \ingroup libusb_hotplug
  1622. * Callback handle.
  1623. *
  1624. * Callbacks handles are generated by libusb_hotplug_register_callback()
  1625. * and can be used to deregister callbacks. Callback handles are unique
  1626. * per libusb_context and it is safe to call libusb_hotplug_deregister_callback()
  1627. * on an already deregistered callback.
  1628. *
  1629. * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102
  1630. *
  1631. * For more information, see \ref libusb_hotplug.
  1632. */
  1633. typedef int libusb_hotplug_callback_handle;
  1634. /** \ingroup libusb_hotplug
  1635. *
  1636. * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102
  1637. *
  1638. * Hotplug events */
  1639. typedef enum {
  1640. /** A device has been plugged in and is ready to use */
  1641. LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = (1 << 0),
  1642. /** A device has left and is no longer available.
  1643. * It is the user's responsibility to call libusb_close on any handle associated with a disconnected device.
  1644. * It is safe to call libusb_get_device_descriptor on a device that has left */
  1645. LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = (1 << 1)
  1646. } libusb_hotplug_event;
  1647. /** \ingroup libusb_hotplug
  1648. *
  1649. * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102
  1650. *
  1651. * Hotplug flags */
  1652. typedef enum {
  1653. /** Arm the callback and fire it for all matching currently attached devices. */
  1654. LIBUSB_HOTPLUG_ENUMERATE = (1 << 0)
  1655. } libusb_hotplug_flag;
  1656. /** \ingroup libusb_hotplug
  1657. * Convenience macro when not using any flags */
  1658. #define LIBUSB_HOTPLUG_NO_FLAGS 0
  1659. /** \ingroup libusb_hotplug
  1660. * Wildcard matching for hotplug events */
  1661. #define LIBUSB_HOTPLUG_MATCH_ANY -1
  1662. /** \ingroup libusb_hotplug
  1663. * Hotplug callback function type. When requesting hotplug event notifications,
  1664. * you pass a pointer to a callback function of this type.
  1665. *
  1666. * This callback may be called by an internal event thread and as such it is
  1667. * recommended the callback do minimal processing before returning.
  1668. *
  1669. * libusb will call this function later, when a matching event had happened on
  1670. * a matching device. See \ref libusb_hotplug for more information.
  1671. *
  1672. * It is safe to call either libusb_hotplug_register_callback() or
  1673. * libusb_hotplug_deregister_callback() from within a callback function.
  1674. *
  1675. * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102
  1676. *
  1677. * \param ctx context of this notification
  1678. * \param device libusb_device this event occurred on
  1679. * \param event event that occurred
  1680. * \param user_data user data provided when this callback was registered
  1681. * \returns bool whether this callback is finished processing events.
  1682. * returning 1 will cause this callback to be deregistered
  1683. */
  1684. typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx,
  1685. libusb_device *device, libusb_hotplug_event event, void *user_data);
  1686. /** \ingroup libusb_hotplug
  1687. * Register a hotplug callback function
  1688. *
  1689. * Register a callback with the libusb_context. The callback will fire
  1690. * when a matching event occurs on a matching device. The callback is
  1691. * armed until either it is deregistered with libusb_hotplug_deregister_callback()
  1692. * or the supplied callback returns 1 to indicate it is finished processing events.
  1693. *
  1694. * If the \ref LIBUSB_HOTPLUG_ENUMERATE is passed the callback will be
  1695. * called with a \ref LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED for all devices
  1696. * already plugged into the machine. Note that libusb modifies its internal
  1697. * device list from a separate thread, while calling hotplug callbacks from
  1698. * libusb_handle_events(), so it is possible for a device to already be present
  1699. * on, or removed from, its internal device list, while the hotplug callbacks
  1700. * still need to be dispatched. This means that when using \ref
  1701. * LIBUSB_HOTPLUG_ENUMERATE, your callback may be called twice for the arrival
  1702. * of the same device, once from libusb_hotplug_register_callback() and once
  1703. * from libusb_handle_events(); and/or your callback may be called for the
  1704. * removal of a device for which an arrived call was never made.
  1705. *
  1706. * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102
  1707. *
  1708. * \param[in] ctx context to register this callback with
  1709. * \param[in] events bitwise or of hotplug events that will trigger this callback.
  1710. * See \ref libusb_hotplug_event
  1711. * \param[in] flags bitwise or of hotplug flags that affect registration.
  1712. * See \ref libusb_hotplug_flag
  1713. * \param[in] vendor_id the vendor id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY
  1714. * \param[in] product_id the product id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY
  1715. * \param[in] dev_class the device class to match or \ref LIBUSB_HOTPLUG_MATCH_ANY
  1716. * \param[in] cb_fn the function to be invoked on a matching event/device
  1717. * \param[in] user_data user data to pass to the callback function
  1718. * \param[out] callback_handle pointer to store the handle of the allocated callback (can be NULL)
  1719. * \returns LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure
  1720. */
  1721. int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx,
  1722. int events, int flags,
  1723. int vendor_id, int product_id, int dev_class,
  1724. libusb_hotplug_callback_fn cb_fn, void *user_data,
  1725. libusb_hotplug_callback_handle *callback_handle);
  1726. /** \ingroup libusb_hotplug
  1727. * Deregisters a hotplug callback.
  1728. *
  1729. * Deregister a callback from a libusb_context. This function is safe to call from within
  1730. * a hotplug callback.
  1731. *
  1732. * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102
  1733. *
  1734. * \param[in] ctx context this callback is registered with
  1735. * \param[in] callback_handle the handle of the callback to deregister
  1736. */
  1737. void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx,
  1738. libusb_hotplug_callback_handle callback_handle);
  1739. /** \ingroup libusb_hotplug
  1740. * Gets the user_data associated with a hotplug callback.
  1741. *
  1742. * Since version v1.0.24 \ref LIBUSB_API_VERSION >= 0x01000108
  1743. *
  1744. * \param[in] ctx context this callback is registered with
  1745. * \param[in] callback_handle the handle of the callback to get the user_data of
  1746. */
  1747. void * LIBUSB_CALL libusb_hotplug_get_user_data(libusb_context *ctx,
  1748. libusb_hotplug_callback_handle callback_handle);
  1749. /** \ingroup libusb_lib
  1750. * Available option values for libusb_set_option().
  1751. */
  1752. enum libusb_option {
  1753. /** Set the log message verbosity.
  1754. *
  1755. * The default level is LIBUSB_LOG_LEVEL_NONE, which means no messages are ever
  1756. * printed. If you choose to increase the message verbosity level, ensure
  1757. * that your application does not close the stderr file descriptor.
  1758. *
  1759. * You are advised to use level LIBUSB_LOG_LEVEL_WARNING. libusb is conservative
  1760. * with its message logging and most of the time, will only log messages that
  1761. * explain error conditions and other oddities. This will help you debug
  1762. * your software.
  1763. *
  1764. * If the LIBUSB_DEBUG environment variable was set when libusb was
  1765. * initialized, this function does nothing: the message verbosity is fixed
  1766. * to the value in the environment variable.
  1767. *
  1768. * If libusb was compiled without any message logging, this function does
  1769. * nothing: you'll never get any messages.
  1770. *
  1771. * If libusb was compiled with verbose debug message logging, this function
  1772. * does nothing: you'll always get messages from all levels.
  1773. */
  1774. LIBUSB_OPTION_LOG_LEVEL = 0,
  1775. /** Use the UsbDk backend for a specific context, if available.
  1776. *
  1777. * This option should be set immediately after calling libusb_init(), otherwise
  1778. * unspecified behavior may occur.
  1779. *
  1780. * Only valid on Windows.
  1781. */
  1782. LIBUSB_OPTION_USE_USBDK = 1,
  1783. /** Do not scan for devices
  1784. *
  1785. * With this option set, libusb will skip scanning devices in
  1786. * libusb_init(). Must be set before calling libusb_init().
  1787. *
  1788. * Hotplug functionality will also be deactivated.
  1789. *
  1790. * The option is useful in combination with libusb_wrap_sys_device(),
  1791. * which can access a device directly without prior device scanning.
  1792. *
  1793. * This is typically needed on Android, where access to USB devices
  1794. * is limited.
  1795. *
  1796. * For LIBUSB_API_VERSION 0x01000108 it was called LIBUSB_OPTION_WEAK_AUTHORITY
  1797. *
  1798. * Only valid on Linux.
  1799. */
  1800. LIBUSB_OPTION_NO_DEVICE_DISCOVERY = 2,
  1801. #define LIBUSB_OPTION_WEAK_AUTHORITY LIBUSB_OPTION_NO_DEVICE_DISCOVERY
  1802. LIBUSB_OPTION_MAX = 3
  1803. };
  1804. int LIBUSB_CALL libusb_set_option(libusb_context *ctx, enum libusb_option option, ...);
  1805. #ifdef _MSC_VER
  1806. #pragma warning(pop)
  1807. #endif
  1808. #if defined(__cplusplus)
  1809. }
  1810. #endif
  1811. #endif