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