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