-
Notifications
You must be signed in to change notification settings - Fork 39
/
libusb.h
1939 lines (1645 loc) · 69.9 KB
/
libusb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Public libusbx header file
* Copyright © 2001 Johannes Erdfelt <[email protected]>
* Copyright © 2007-2008 Daniel Drake <[email protected]>
* Copyright © 2012 Pete Batard <[email protected]>
* Copyright © 2012 Nathan Hjelm <[email protected]>
* For more information, please visit: http://libusbx.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LIBUSB_H
#define LIBUSB_H
#ifdef _MSC_VER
/* on MS environments, the inline keyword is available in C++ only */
#if !defined(__cplusplus)
#define inline __inline
#endif
/* ssize_t is also not available (copy/paste from MinGW) */
#ifndef _SSIZE_T_DEFINED
#define _SSIZE_T_DEFINED
#undef ssize_t
#ifdef _WIN64
typedef __int64 ssize_t;
#else
typedef int ssize_t;
#endif /* _WIN64 */
#endif /* _SSIZE_T_DEFINED */
#endif /* _MSC_VER */
/* stdint.h is not available on older MSVC */
#if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
#else
#include <stdint.h>
#endif
#if !defined(_WIN32_WCE)
#include <sys/types.h>
#endif
#if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__)
#include <sys/time.h>
#endif
#include <time.h>
#include <limits.h>
/* 'interface' might be defined as a macro on Windows, so we need to
* undefine it so as not to break the current libusbx API, because
* libusb_config_descriptor has an 'interface' member
* As this can be problematic if you include windows.h after libusb.h
* in your sources, we force windows.h to be included first. */
#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
#include <windows.h>
#if defined(interface)
#undef interface
#endif
#if !defined(__CYGWIN__)
#include <winsock.h>
#endif
#endif
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define LIBUSB_DEPRECATED_FOR(f) \
__attribute__((deprecated("Use " #f " instead")))
#else
#define LIBUSB_DEPRECATED_FOR(f)
#endif /* __GNUC__ */
#ifdef Q_OS_WIN
#pragma warning( disable : 4200 )
#endif
/** \def LIBUSB_CALL
* \ingroup misc
* libusbx's Windows calling convention.
*
* Under Windows, the selection of available compilers and configurations
* means that, unlike other platforms, there is not <em>one true calling
* convention</em> (calling convention: the manner in which parameters are
* passed to funcions in the generated assembly code).
*
* Matching the Windows API itself, libusbx uses the WINAPI convention (which
* translates to the <tt>stdcall</tt> convention) and guarantees that the
* library is compiled in this way. The public header file also includes
* appropriate annotations so that your own software will use the right
* convention, even if another convention is being used by default within
* your codebase.
*
* The one consideration that you must apply in your software is to mark
* all functions which you use as libusbx callbacks with this LIBUSB_CALL
* annotation, so that they too get compiled for the correct calling
* convention.
*
* On non-Windows operating systems, this macro is defined as nothing. This
* means that you can apply it to your code without worrying about
* cross-platform compatibility.
*/
/* LIBUSB_CALL must be defined on both definition and declaration of libusbx
* functions. You'd think that declaration would be enough, but cygwin will
* complain about conflicting types unless both are marked this way.
* The placement of this macro is important too; it must appear after the
* return type, before the function name. See internal documentation for
* API_EXPORTED.
*/
#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
#define LIBUSB_CALL WINAPI
#else
#define LIBUSB_CALL
#endif
/** \def LIBUSBX_API_VERSION
* \ingroup misc
* libusbx's API version.
*
* Since version 1.0.13, to help with feature detection, libusbx defines
* a LIBUSBX_API_VERSION macro that gets increased every time there is a
* significant change to the API, such as the introduction of a new call,
* the definition of a new macro/enum member, or any other element that
* libusbx applications may want to detect at compilation time.
*
* The macro is typically used in an application as follows:
* \code
* #if defined(LIBUSBX_API_VERSION) && (LIBUSBX_API_VERSION >= 0x01001234)
* // Use one of the newer features from the libusbx API
* #endif
* \endcode
*
* Another feature of LIBUSBX_API_VERSION is that it can be used to detect
* whether you are compiling against the libusb or the libusbx library.
*
* Internally, LIBUSBX_API_VERSION is defined as follows:
* (libusbx major << 24) | (libusbx minor << 16) | (16 bit incremental)
*/
#define LIBUSBX_API_VERSION 0x01000102
#ifdef __cplusplus
extern "C" {
#endif
/** \fn libusb_cpu_to_le16
* \ingroup misc
* Convert a 16-bit value from host-endian to little-endian format. On
* little endian systems, this function does nothing. On big endian systems,
* the bytes are swapped.
* \param x the host-endian value to convert
* \returns the value in little-endian byte order
*/
static inline uint16_t libusb_cpu_to_le16(const uint16_t x) {
union {
uint8_t b8[2];
uint16_t b16;
} _tmp;
_tmp.b8[1] = (uint8_t)(x >> 8);
_tmp.b8[0] = (uint8_t)(x & 0xff);
return _tmp.b16;
}
/** \def libusb_le16_to_cpu
* \ingroup misc
* Convert a 16-bit value from little-endian to host-endian format. On
* little endian systems, this function does nothing. On big endian systems,
* the bytes are swapped.
* \param x the little-endian value to convert
* \returns the value in host-endian byte order
*/
#define libusb_le16_to_cpu libusb_cpu_to_le16
/* standard USB stuff */
/** \ingroup desc
* Device and/or Interface Class codes */
enum libusb_class_code {
/** In the context of a \ref libusb_device_descriptor "device descriptor",
* this bDeviceClass value indicates that each interface specifies its
* own class information and all interfaces operate independently.
*/
LIBUSB_CLASS_PER_INTERFACE = 0,
/** Audio class */
LIBUSB_CLASS_AUDIO = 1,
/** Communications class */
LIBUSB_CLASS_COMM = 2,
/** Human Interface Device class */
LIBUSB_CLASS_HID = 3,
/** Physical */
LIBUSB_CLASS_PHYSICAL = 5,
/** Printer class */
LIBUSB_CLASS_PRINTER = 7,
/** Image class */
LIBUSB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */
LIBUSB_CLASS_IMAGE = 6,
/** Mass storage class */
LIBUSB_CLASS_MASS_STORAGE = 8,
/** Hub class */
LIBUSB_CLASS_HUB = 9,
/** Data class */
LIBUSB_CLASS_DATA = 10,
/** Smart Card */
LIBUSB_CLASS_SMART_CARD = 0x0b,
/** Content Security */
LIBUSB_CLASS_CONTENT_SECURITY = 0x0d,
/** Video */
LIBUSB_CLASS_VIDEO = 0x0e,
/** Personal Healthcare */
LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
/** Diagnostic Device */
LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
/** Wireless class */
LIBUSB_CLASS_WIRELESS = 0xe0,
/** Application class */
LIBUSB_CLASS_APPLICATION = 0xfe,
/** Class is vendor-specific */
LIBUSB_CLASS_VENDOR_SPEC = 0xff
};
/** \ingroup desc
* Descriptor types as defined by the USB specification. */
enum libusb_descriptor_type {
/** Device descriptor. See libusb_device_descriptor. */
LIBUSB_DT_DEVICE = 0x01,
/** Configuration descriptor. See libusb_config_descriptor. */
LIBUSB_DT_CONFIG = 0x02,
/** String descriptor */
LIBUSB_DT_STRING = 0x03,
/** Interface descriptor. See libusb_interface_descriptor. */
LIBUSB_DT_INTERFACE = 0x04,
/** Endpoint descriptor. See libusb_endpoint_descriptor. */
LIBUSB_DT_ENDPOINT = 0x05,
/** BOS descriptor */
LIBUSB_DT_BOS = 0x0f,
/** Device Capability descriptor */
LIBUSB_DT_DEVICE_CAPABILITY = 0x10,
/** HID descriptor */
LIBUSB_DT_HID = 0x21,
/** HID report descriptor */
LIBUSB_DT_REPORT = 0x22,
/** Physical descriptor */
LIBUSB_DT_PHYSICAL = 0x23,
/** Hub descriptor */
LIBUSB_DT_HUB = 0x29,
/** SuperSpeed Hub descriptor */
LIBUSB_DT_SUPERSPEED_HUB = 0x2a,
/** SuperSpeed Endpoint Companion descriptor */
LIBUSB_DT_SS_ENDPOINT_COMPANION = 0x30
};
/* Descriptor sizes per descriptor type */
#define LIBUSB_DT_DEVICE_SIZE 18
#define LIBUSB_DT_CONFIG_SIZE 9
#define LIBUSB_DT_INTERFACE_SIZE 9
#define LIBUSB_DT_ENDPOINT_SIZE 7
#define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
#define LIBUSB_DT_HUB_NONVAR_SIZE 7
#define LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE 6
#define LIBUSB_DT_BOS_SIZE 5
#define LIBUSB_DT_DEVICE_CAPABILITY_SIZE 3
/* BOS descriptor sizes */
#define LIBUSB_BT_USB_2_0_EXTENSION_SIZE 7
#define LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE 10
#define LIBUSB_BT_CONTAINER_ID_SIZE 20
/* We unwrap the BOS => define its max size */
#define LIBUSB_DT_BOS_MAX_SIZE ((LIBUSB_DT_BOS_SIZE) +\
(LIBUSB_BT_USB_2_0_EXTENSION_SIZE) +\
(LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE) +\
(LIBUSB_BT_CONTAINER_ID_SIZE))
#define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
#define LIBUSB_ENDPOINT_DIR_MASK 0x80
/** \ingroup desc
* Endpoint direction. Values for bit 7 of the
* \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
*/
enum libusb_endpoint_direction {
/** In: device-to-host */
LIBUSB_ENDPOINT_IN = 0x80,
/** Out: host-to-device */
LIBUSB_ENDPOINT_OUT = 0x00
};
#define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */
/** \ingroup desc
* Endpoint transfer type. Values for bits 0:1 of the
* \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
*/
enum libusb_transfer_type {
/** Control endpoint */
LIBUSB_TRANSFER_TYPE_CONTROL = 0,
/** Isochronous endpoint */
LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
/** Bulk endpoint */
LIBUSB_TRANSFER_TYPE_BULK = 2,
/** Interrupt endpoint */
LIBUSB_TRANSFER_TYPE_INTERRUPT = 3
};
/** \ingroup misc
* Standard requests, as defined in table 9-5 of the USB 3.0 specifications */
enum libusb_standard_request {
/** Request status of the specific recipient */
LIBUSB_REQUEST_GET_STATUS = 0x00,
/** Clear or disable a specific feature */
LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
/* 0x02 is reserved */
/** Set or enable a specific feature */
LIBUSB_REQUEST_SET_FEATURE = 0x03,
/* 0x04 is reserved */
/** Set device address for all future accesses */
LIBUSB_REQUEST_SET_ADDRESS = 0x05,
/** Get the specified descriptor */
LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
/** Used to update existing descriptors or add new descriptors */
LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
/** Get the current device configuration value */
LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
/** Set device configuration */
LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
/** Return the selected alternate setting for the specified interface */
LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
/** Select an alternate interface for the specified interface */
LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
/** Set then report an endpoint's synchronization frame */
LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
/** Sets both the U1 and U2 Exit Latency */
LIBUSB_REQUEST_SET_SEL = 0x30,
/** Delay from the time a host transmits a packet to the time it is
* received by the device. */
LIBUSB_SET_ISOCH_DELAY = 0x31,
};
/** \ingroup misc
* Request type bits of the
* \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
* transfers. */
enum libusb_request_type {
/** Standard */
LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
/** Class */
LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
/** Vendor */
LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
/** Reserved */
LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)
};
/** \ingroup misc
* Recipient bits of the
* \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
* transfers. Values 4 through 31 are reserved. */
enum libusb_request_recipient {
/** Device */
LIBUSB_RECIPIENT_DEVICE = 0x00,
/** Interface */
LIBUSB_RECIPIENT_INTERFACE = 0x01,
/** Endpoint */
LIBUSB_RECIPIENT_ENDPOINT = 0x02,
/** Other */
LIBUSB_RECIPIENT_OTHER = 0x03,
};
#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
/** \ingroup desc
* Synchronization type for isochronous endpoints. Values for bits 2:3 of the
* \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
* libusb_endpoint_descriptor.
*/
enum libusb_iso_sync_type {
/** No synchronization */
LIBUSB_ISO_SYNC_TYPE_NONE = 0,
/** Asynchronous */
LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
/** Adaptive */
LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
/** Synchronous */
LIBUSB_ISO_SYNC_TYPE_SYNC = 3
};
#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
/** \ingroup desc
* Usage type for isochronous endpoints. Values for bits 4:5 of the
* \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
* libusb_endpoint_descriptor.
*/
enum libusb_iso_usage_type {
/** Data endpoint */
LIBUSB_ISO_USAGE_TYPE_DATA = 0,
/** Feedback endpoint */
LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
/** Implicit feedback Data endpoint */
LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
};
/** \ingroup desc
* A structure representing the standard USB device descriptor. This
* descriptor is documented in section 9.6.1 of the USB 3.0 specification.
* All multiple-byte fields are represented in host-endian format.
*/
struct libusb_device_descriptor {
/** Size of this descriptor (in bytes) */
uint8_t bLength;
/** Descriptor type. Will have value
* \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this
* context. */
uint8_t bDescriptorType;
/** USB specification release number in binary-coded decimal. A value of
* 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
uint16_t bcdUSB;
/** USB-IF class code for the device. See \ref libusb_class_code. */
uint8_t bDeviceClass;
/** USB-IF subclass code for the device, qualified by the bDeviceClass
* value */
uint8_t bDeviceSubClass;
/** USB-IF protocol code for the device, qualified by the bDeviceClass and
* bDeviceSubClass values */
uint8_t bDeviceProtocol;
/** Maximum packet size for endpoint 0 */
uint8_t bMaxPacketSize0;
/** USB-IF vendor ID */
uint16_t idVendor;
/** USB-IF product ID */
uint16_t idProduct;
/** Device release number in binary-coded decimal */
uint16_t bcdDevice;
/** Index of string descriptor describing manufacturer */
uint8_t iManufacturer;
/** Index of string descriptor describing product */
uint8_t iProduct;
/** Index of string descriptor containing device serial number */
uint8_t iSerialNumber;
/** Number of possible configurations */
uint8_t bNumConfigurations;
};
/** \ingroup desc
* A structure representing the standard USB endpoint descriptor. This
* descriptor is documented in section 9.6.6 of the USB 3.0 specification.
* All multiple-byte fields are represented in host-endian format.
*/
struct libusb_endpoint_descriptor {
/** Size of this descriptor (in bytes) */
uint8_t bLength;
/** Descriptor type. Will have value
* \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in
* this context. */
uint8_t bDescriptorType;
/** The address of the endpoint described by this descriptor. Bits 0:3 are
* the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,
* see \ref libusb_endpoint_direction.
*/
uint8_t bEndpointAddress;
/** Attributes which apply to the endpoint when it is configured using
* the bConfigurationValue. Bits 0:1 determine the transfer type and
* correspond to \ref libusb_transfer_type. Bits 2:3 are only used for
* isochronous endpoints and correspond to \ref libusb_iso_sync_type.
* Bits 4:5 are also only used for isochronous endpoints and correspond to
* \ref libusb_iso_usage_type. Bits 6:7 are reserved.
*/
uint8_t bmAttributes;
/** Maximum packet size this endpoint is capable of sending/receiving. */
uint16_t wMaxPacketSize;
/** Interval for polling endpoint for data transfers. */
uint8_t bInterval;
/** For audio devices only: the rate at which synchronization feedback
* is provided. */
uint8_t bRefresh;
/** For audio devices only: the address if the synch endpoint */
uint8_t bSynchAddress;
/** Extra descriptors. If libusbx encounters unknown endpoint descriptors,
* it will store them here, should you wish to parse them. */
const unsigned char *extra;
/** Length of the extra descriptors, in bytes. */
int extra_length;
};
/** \ingroup desc
* A structure representing the standard USB interface descriptor. This
* descriptor is documented in section 9.6.5 of the USB 3.0 specification.
* All multiple-byte fields are represented in host-endian format.
*/
struct libusb_interface_descriptor {
/** Size of this descriptor (in bytes) */
uint8_t bLength;
/** Descriptor type. Will have value
* \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE
* in this context. */
uint8_t bDescriptorType;
/** Number of this interface */
uint8_t bInterfaceNumber;
/** Value used to select this alternate setting for this interface */
uint8_t bAlternateSetting;
/** Number of endpoints used by this interface (excluding the control
* endpoint). */
uint8_t bNumEndpoints;
/** USB-IF class code for this interface. See \ref libusb_class_code. */
uint8_t bInterfaceClass;
/** USB-IF subclass code for this interface, qualified by the
* bInterfaceClass value */
uint8_t bInterfaceSubClass;
/** USB-IF protocol code for this interface, qualified by the
* bInterfaceClass and bInterfaceSubClass values */
uint8_t bInterfaceProtocol;
/** Index of string descriptor describing this interface */
uint8_t iInterface;
/** Array of endpoint descriptors. This length of this array is determined
* by the bNumEndpoints field. */
const struct libusb_endpoint_descriptor *endpoint;
/** Extra descriptors. If libusbx encounters unknown interface descriptors,
* it will store them here, should you wish to parse them. */
const unsigned char *extra;
/** Length of the extra descriptors, in bytes. */
int extra_length;
};
/** \ingroup desc
* A collection of alternate settings for a particular USB interface.
*/
struct libusb_interface {
/** Array of interface descriptors. The length of this array is determined
* by the num_altsetting field. */
const struct libusb_interface_descriptor *altsetting;
/** The number of alternate settings that belong to this interface */
int num_altsetting;
};
/** \ingroup desc
* A structure representing the standard USB configuration descriptor. This
* descriptor is documented in section 9.6.3 of the USB 3.0 specification.
* All multiple-byte fields are represented in host-endian format.
*/
struct libusb_config_descriptor {
/** Size of this descriptor (in bytes) */
uint8_t bLength;
/** Descriptor type. Will have value
* \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG
* in this context. */
uint8_t bDescriptorType;
/** Total length of data returned for this configuration */
uint16_t wTotalLength;
/** Number of interfaces supported by this configuration */
uint8_t bNumInterfaces;
/** Identifier value for this configuration */
uint8_t bConfigurationValue;
/** Index of string descriptor describing this configuration */
uint8_t iConfiguration;
/** Configuration characteristics */
uint8_t bmAttributes;
/** Maximum power consumption of the USB device from this bus in this
* configuration when the device is fully opreation. Expressed in units
* of 2 mA. */
uint8_t MaxPower;
/** Array of interfaces supported by this configuration. The length of
* this array is determined by the bNumInterfaces field. */
const struct libusb_interface *interface;
/** Extra descriptors. If libusbx encounters unknown configuration
* descriptors, it will store them here, should you wish to parse them. */
const unsigned char *extra;
/** Length of the extra descriptors, in bytes. */
int extra_length;
};
/** \ingroup desc
* A structure representing the superspeed endpoint companion
* descriptor. This descriptor is documented in section 9.6.7 of
* the USB 3.0 specification. All multiple-byte fields are represented in
* host-endian format.
*/
struct libusb_ss_endpoint_companion_descriptor {
/** Size of this descriptor (in bytes) */
uint8_t bLength;
/** Descriptor type. Will have value
* \ref libusb_descriptor_type::LIBUSB_DT_SS_ENDPOINT_COMPANION in
* this context. */
uint8_t bDescriptorType;
/** The maximum number of packets the endpoint can send or
* recieve as part of a burst. */
uint8_t bMaxBurst;
/** In bulk EP: bits 4:0 represents the maximum number of
* streams the EP supports. In isochronous EP: bits 1:0
* represents the Mult - a zero based value that determines
* the maximum number of packets within a service interval */
uint8_t bmAttributes;
/** The total number of bytes this EP will transfer every
* service interval. valid only for periodic EPs. */
uint16_t wBytesPerInterval;
};
/** \ingroup desc
* A generic representation of a BOS Device Capability descriptor. It is
* advised to check bDevCapabilityType and call the matching
* libusb_get_*_descriptor function to get a structure fully matching the type.
*/
struct libusb_bos_dev_capability_descriptor {
/** Size of this descriptor (in bytes) */
uint8_t bLength;
/** Descriptor type. Will have value
* \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
* LIBUSB_DT_DEVICE_CAPABILITY in this context. */
uint8_t bDescriptorType;
/** Device Capability type */
uint8_t bDevCapabilityType;
/** Device Capability data (bLength - 3 bytes) */
uint8_t dev_capability_data
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
[] /* valid C99 code */
#else
[0] /* non-standard, but usually working code */
#endif
;
};
/** \ingroup desc
* A structure representing the Binary Device Object Store (BOS) descriptor.
* This descriptor is documented in section 9.6.2 of the USB 3.0 specification.
* All multiple-byte fields are represented in host-endian format.
*/
struct libusb_bos_descriptor {
/** Size of this descriptor (in bytes) */
uint8_t bLength;
/** Descriptor type. Will have value
* \ref libusb_descriptor_type::LIBUSB_DT_BOS LIBUSB_DT_BOS
* in this context. */
uint8_t bDescriptorType;
/** Length of this descriptor and all of its sub descriptors */
uint16_t wTotalLength;
/** The number of separate device capability descriptors in
* the BOS */
uint8_t bNumDeviceCaps;
/** bNumDeviceCap Device Capability Descriptors */
struct libusb_bos_dev_capability_descriptor *dev_capability
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
[] /* valid C99 code */
#else
[0] /* non-standard, but usually working code */
#endif
;
};
/** \ingroup desc
* A structure representing the USB 2.0 Extension descriptor
* This descriptor is documented in section 9.6.2.1 of the USB 3.0 specification.
* All multiple-byte fields are represented in host-endian format.
*/
struct libusb_usb_2_0_extension_descriptor {
/** Size of this descriptor (in bytes) */
uint8_t bLength;
/** Descriptor type. Will have value
* \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
* LIBUSB_DT_DEVICE_CAPABILITY in this context. */
uint8_t bDescriptorType;
/** Capability type. Will have value
* \ref libusb_capability_type::LIBUSB_BT_USB_2_0_EXTENSION
* LIBUSB_BT_USB_2_0_EXTENSION in this context. */
uint8_t bDevCapabilityType;
/** Bitmap encoding of supported device level features.
* A value of one in a bit location indicates a feature is
* supported; a value of zero indicates it is not supported.
* See \ref libusb_usb_2_0_extension_attributes. */
uint32_t bmAttributes;
};
/** \ingroup desc
* A structure representing the SuperSpeed USB Device Capability descriptor
* This descriptor is documented in section 9.6.2.2 of the USB 3.0 specification.
* All multiple-byte fields are represented in host-endian format.
*/
struct libusb_ss_usb_device_capability_descriptor {
/** Size of this descriptor (in bytes) */
uint8_t bLength;
/** Descriptor type. Will have value
* \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
* LIBUSB_DT_DEVICE_CAPABILITY in this context. */
uint8_t bDescriptorType;
/** Capability type. Will have value
* \ref libusb_capability_type::LIBUSB_BT_SS_USB_DEVICE_CAPABILITY
* LIBUSB_BT_SS_USB_DEVICE_CAPABILITY in this context. */
uint8_t bDevCapabilityType;
/** Bitmap encoding of supported device level features.
* A value of one in a bit location indicates a feature is
* supported; a value of zero indicates it is not supported.
* See \ref libusb_ss_usb_device_capability_attributes. */
uint8_t bmAttributes;
/** Bitmap encoding of the speed supported by this device when
* operating in SuperSpeed mode. See \ref libusb_supported_speed. */
uint16_t wSpeedSupported;
/** The lowest speed at which all the functionality supported
* by the device is available to the user. For example if the
* device supports all its functionality when connected at
* full speed and above then it sets this value to 1. */
uint8_t bFunctionalitySupport;
/** U1 Device Exit Latency. */
uint8_t bU1DevExitLat;
/** U2 Device Exit Latency. */
uint16_t bU2DevExitLat;
};
/** \ingroup desc
* A structure representing the Container ID descriptor.
* This descriptor is documented in section 9.6.2.3 of the USB 3.0 specification.
* All multiple-byte fields, except UUIDs, are represented in host-endian format.
*/
struct libusb_container_id_descriptor {
/** Size of this descriptor (in bytes) */
uint8_t bLength;
/** Descriptor type. Will have value
* \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
* LIBUSB_DT_DEVICE_CAPABILITY in this context. */
uint8_t bDescriptorType;
/** Capability type. Will have value
* \ref libusb_capability_type::LIBUSB_BT_CONTAINER_ID
* LIBUSB_BT_CONTAINER_ID in this context. */
uint8_t bDevCapabilityType;
/** Reserved field */
uint8_t bReserved;
/** 128 bit UUID */
uint8_t ContainerID[16];
};
/** \ingroup asyncio
* Setup packet for control transfers. */
struct libusb_control_setup {
/** Request type. Bits 0:4 determine recipient, see
* \ref libusb_request_recipient. Bits 5:6 determine type, see
* \ref libusb_request_type. Bit 7 determines data transfer direction, see
* \ref libusb_endpoint_direction.
*/
uint8_t bmRequestType;
/** Request. If the type bits of bmRequestType are equal to
* \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD
* "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to
* \ref libusb_standard_request. For other cases, use of this field is
* application-specific. */
uint8_t bRequest;
/** Value. Varies according to request */
uint16_t wValue;
/** Index. Varies according to request, typically used to pass an index
* or offset */
uint16_t wIndex;
/** Number of bytes to transfer */
uint16_t wLength;
};
#define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
/* libusbx */
struct libusb_context;
struct libusb_device;
struct libusb_device_handle;
struct libusb_hotplug_callback;
/** \ingroup lib
* Structure providing the version of the libusbx runtime
*/
struct libusb_version {
/** Library major version. */
const uint16_t major;
/** Library minor version. */
const uint16_t minor;
/** Library micro version. */
const uint16_t micro;
/** Library nano version. */
const uint16_t nano;
/** Library release candidate suffix string, e.g. "-rc4". */
const char *rc;
/** For ABI compatibility only. */
const char *describe;
};
/** \ingroup lib
* Structure representing a libusbx session. The concept of individual libusbx
* sessions allows for your program to use two libraries (or dynamically
* load two modules) which both independently use libusb. This will prevent
* interference between the individual libusbx users - for example
* libusb_set_debug() will not affect the other user of the library, and
* libusb_exit() will not destroy resources that the other user is still
* using.
*
* Sessions are created by libusb_init() and destroyed through libusb_exit().
* If your application is guaranteed to only ever include a single libusbx
* user (i.e. you), you do not have to worry about contexts: pass NULL in
* every function call where a context is required. The default context
* will be used.
*
* For more information, see \ref contexts.
*/
typedef struct libusb_context libusb_context;
/** \ingroup dev
* Structure representing a USB device detected on the system. This is an
* opaque type for which you are only ever provided with a pointer, usually
* originating from libusb_get_device_list().
*
* Certain operations can be performed on a device, but in order to do any
* I/O you will have to first obtain a device handle using libusb_open().
*
* Devices are reference counted with libusb_ref_device() and
* libusb_unref_device(), and are freed when the reference count reaches 0.
* New devices presented by libusb_get_device_list() have a reference count of
* 1, and libusb_free_device_list() can optionally decrease the reference count
* on all devices in the list. libusb_open() adds another reference which is
* later destroyed by libusb_close().
*/
typedef struct libusb_device libusb_device;
/** \ingroup dev
* Structure representing a handle on a USB device. This is an opaque type for
* which you are only ever provided with a pointer, usually originating from
* libusb_open().
*
* A device handle is used to perform I/O and other operations. When finished
* with a device handle, you should call libusb_close().
*/
typedef struct libusb_device_handle libusb_device_handle;
/** \ingroup dev
* Speed codes. Indicates the speed at which the device is operating.
*/
enum libusb_speed {
/** The OS doesn't report or know the device speed. */
LIBUSB_SPEED_UNKNOWN = 0,
/** The device is operating at low speed (1.5MBit/s). */
LIBUSB_SPEED_LOW = 1,
/** The device is operating at full speed (12MBit/s). */
LIBUSB_SPEED_FULL = 2,
/** The device is operating at high speed (480MBit/s). */
LIBUSB_SPEED_HIGH = 3,
/** The device is operating at super speed (5000MBit/s). */
LIBUSB_SPEED_SUPER = 4,
};
/** \ingroup dev
* Supported speeds (wSpeedSupported) bitfield. Indicates what
* speeds the device supports.
*/
enum libusb_supported_speed {
/** Low speed operation supported (1.5MBit/s). */
LIBUSB_LOW_SPEED_OPERATION = 1,
/** Full speed operation supported (12MBit/s). */