libusb 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Gemfile +1 -0
  5. data/History.md +10 -0
  6. data/README.md +19 -6
  7. data/Rakefile +1 -1
  8. data/ext/extconf.rb +17 -1
  9. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/AUTHORS +18 -6
  10. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/COPYING +0 -0
  11. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/ChangeLog +58 -1
  12. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/INSTALL +0 -0
  13. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/Makefile.am +6 -1
  14. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/Makefile.in +248 -174
  15. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/NEWS +2 -2
  16. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/PORTING +0 -0
  17. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/README +2 -1
  18. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/TODO +0 -0
  19. data/ext/libusbx-1.0.17/Xcode/common.xcconfig +40 -0
  20. data/ext/libusbx-1.0.17/Xcode/config.h +28 -0
  21. data/ext/libusbx-1.0.17/Xcode/debug.xcconfig +29 -0
  22. data/ext/libusbx-1.0.17/Xcode/libusbx.xcconfig +21 -0
  23. data/ext/libusbx-1.0.17/Xcode/libusbx.xcodeproj/project.pbxproj +864 -0
  24. data/ext/libusbx-1.0.17/Xcode/libusbx_debug.xcconfig +21 -0
  25. data/ext/libusbx-1.0.17/Xcode/libusbx_release.xcconfig +21 -0
  26. data/ext/libusbx-1.0.17/Xcode/release.xcconfig +29 -0
  27. data/ext/libusbx-1.0.17/aclocal.m4 +1112 -0
  28. data/ext/libusbx-1.0.17/android/README +114 -0
  29. data/ext/libusbx-1.0.17/android/config.h +90 -0
  30. data/ext/libusbx-1.0.17/android/jni/Android.mk +23 -0
  31. data/ext/libusbx-1.0.17/android/jni/Application.mk +19 -0
  32. data/ext/libusbx-1.0.17/android/jni/examples.mk +134 -0
  33. data/ext/libusbx-1.0.17/android/jni/libusb.mk +54 -0
  34. data/ext/libusbx-1.0.17/android/jni/tests.mk +56 -0
  35. data/ext/libusbx-1.0.17/compile +347 -0
  36. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/config.guess +164 -130
  37. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/config.h.in +37 -1
  38. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/config.sub +174 -89
  39. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/configure +723 -302
  40. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/configure.ac +71 -20
  41. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/depcomp +345 -185
  42. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/doc/Makefile.am +0 -0
  43. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/doc/Makefile.in +95 -32
  44. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/doc/doxygen.cfg.in +1 -1
  45. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/examples/Makefile.am +5 -4
  46. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/examples/Makefile.in +208 -104
  47. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/examples/dpfp.c +1 -1
  48. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/examples/dpfp_threaded.c +1 -1
  49. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/examples/ezusb.c +188 -8
  50. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/examples/ezusb.h +18 -5
  51. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/examples/fxload.c +90 -64
  52. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/examples/getopt/getopt.c +0 -0
  53. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/examples/getopt/getopt.h +0 -0
  54. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/examples/getopt/getopt1.c +0 -0
  55. data/ext/libusbx-1.0.17/examples/hotplugtest.c +97 -0
  56. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/examples/listdevs.c +12 -4
  57. data/ext/libusbx-1.0.17/examples/sam3u_benchmark.c +193 -0
  58. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/examples/xusb.c +106 -49
  59. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/install-sh +21 -14
  60. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb-1.0.pc.in +1 -1
  61. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/Makefile.am +29 -10
  62. data/ext/libusbx-1.0.17/libusb/Makefile.in +914 -0
  63. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/core.c +378 -87
  64. data/ext/libusbx-1.0.17/libusb/descriptor.c +1199 -0
  65. data/ext/libusbx-1.0.17/libusb/hotplug.c +322 -0
  66. data/ext/libusbx-1.0.17/libusb/hotplug.h +82 -0
  67. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/io.c +182 -62
  68. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/libusb-1.0.def +32 -0
  69. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/libusb-1.0.rc +2 -0
  70. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/libusb.h +481 -32
  71. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/libusbi.h +135 -38
  72. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/os/darwin_usb.c +591 -496
  73. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/os/darwin_usb.h +39 -46
  74. data/ext/libusbx-1.0.17/libusb/os/linux_netlink.c +345 -0
  75. data/ext/libusbx-1.0.17/libusb/os/linux_udev.c +306 -0
  76. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/os/linux_usbfs.c +653 -617
  77. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/os/linux_usbfs.h +32 -0
  78. data/ext/{libusbx-1.0.14/libusb/os/openbsd_usb.c → libusbx-1.0.17/libusb/os/netbsd_usb.c} +70 -63
  79. data/ext/libusbx-1.0.17/libusb/os/openbsd_usb.c +823 -0
  80. data/ext/libusbx-1.0.17/libusb/os/poll_posix.c +51 -0
  81. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/os/poll_posix.h +2 -1
  82. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/os/poll_windows.c +85 -106
  83. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/os/poll_windows.h +14 -3
  84. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/os/threads_posix.c +3 -1
  85. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/os/threads_posix.h +0 -0
  86. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/os/threads_windows.c +6 -5
  87. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/os/threads_windows.h +0 -0
  88. data/ext/libusbx-1.0.17/libusb/os/wince_usb.c +1026 -0
  89. data/ext/libusbx-1.0.17/libusb/os/wince_usb.h +131 -0
  90. data/ext/libusbx-1.0.17/libusb/os/windows_common.h +108 -0
  91. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/os/windows_usb.c +92 -57
  92. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/os/windows_usb.h +2 -63
  93. data/ext/libusbx-1.0.17/libusb/strerror.c +184 -0
  94. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/sync.c +24 -38
  95. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/libusb/version.h +1 -1
  96. data/ext/libusbx-1.0.17/libusb/version_nano.h +1 -0
  97. data/ext/{libusbx-1.0.14 → libusbx-1.0.17}/ltmain.sh +60 -41
  98. data/ext/{libusbx-1.0.14/aclocal.m4 → libusbx-1.0.17/m4/libtool.m4} +229 -1723
  99. data/ext/libusbx-1.0.17/m4/ltoptions.m4 +384 -0
  100. data/ext/libusbx-1.0.17/m4/ltsugar.m4 +123 -0
  101. data/ext/libusbx-1.0.17/m4/ltversion.m4 +23 -0
  102. data/ext/libusbx-1.0.17/m4/lt~obsolete.m4 +98 -0
  103. data/ext/libusbx-1.0.17/missing +215 -0
  104. data/ext/libusbx-1.0.17/tests/Makefile.am +6 -0
  105. data/ext/libusbx-1.0.17/tests/Makefile.in +583 -0
  106. data/ext/libusbx-1.0.17/tests/libusbx_testlib.h +107 -0
  107. data/ext/libusbx-1.0.17/tests/stress.c +160 -0
  108. data/ext/libusbx-1.0.17/tests/testlib.c +276 -0
  109. data/lib/libusb.rb +4 -0
  110. data/lib/libusb/call.rb +43 -1
  111. data/lib/libusb/constants.rb +5 -0
  112. data/lib/libusb/context.rb +100 -0
  113. data/lib/libusb/dev_handle.rb +27 -0
  114. data/lib/libusb/device.rb +10 -4
  115. data/lib/libusb/version_gem.rb +1 -1
  116. data/test/test_libusb_capability.rb +2 -2
  117. data/test/test_libusb_compat.rb +2 -2
  118. data/test/test_libusb_compat_mass_storage.rb +2 -2
  119. data/test/test_libusb_descriptors.rb +4 -2
  120. data/test/test_libusb_event_machine.rb +2 -2
  121. data/test/test_libusb_gc.rb +2 -2
  122. data/test/test_libusb_hotplug.rb +115 -0
  123. data/test/test_libusb_iso_transfer.rb +3 -3
  124. data/test/test_libusb_mass_storage.rb +6 -16
  125. data/test/test_libusb_mass_storage2.rb +26 -3
  126. data/test/test_libusb_structs.rb +2 -2
  127. data/test/test_libusb_threads.rb +2 -2
  128. data/test/test_libusb_version.rb +2 -2
  129. metadata +127 -68
  130. metadata.gz.sig +0 -0
  131. data/ext/libusbx-1.0.14/THANKS +0 -7
  132. data/ext/libusbx-1.0.14/compile +0 -143
  133. data/ext/libusbx-1.0.14/libusb/Makefile.in +0 -721
  134. data/ext/libusbx-1.0.14/libusb/descriptor.c +0 -731
  135. data/ext/libusbx-1.0.14/libusb/version_nano.h +0 -1
  136. data/ext/libusbx-1.0.14/missing +0 -376
@@ -26,14 +26,26 @@ EXPORTS
26
26
  libusb_event_handling_ok@4 = libusb_event_handling_ok
27
27
  libusb_exit
28
28
  libusb_exit@4 = libusb_exit
29
+ libusb_free_bos_descriptor
30
+ libusb_free_bos_descriptor@4 = libusb_free_bos_descriptor
29
31
  libusb_free_config_descriptor
30
32
  libusb_free_config_descriptor@4 = libusb_free_config_descriptor
33
+ libusb_free_container_id_descriptor
34
+ libusb_free_container_id_descriptor@4 = libusb_free_container_id_descriptor
31
35
  libusb_free_device_list
32
36
  libusb_free_device_list@8 = libusb_free_device_list
37
+ libusb_free_ss_endpoint_companion_descriptor
38
+ libusb_free_ss_endpoint_companion_descriptor@4 = libusb_free_ss_endpoint_companion_descriptor
39
+ libusb_free_ss_usb_device_capability_descriptor
40
+ libusb_free_ss_usb_device_capability_descriptor@4 = libusb_free_ss_usb_device_capability_descriptor
33
41
  libusb_free_transfer
34
42
  libusb_free_transfer@4 = libusb_free_transfer
43
+ libusb_free_usb_2_0_extension_descriptor
44
+ libusb_free_usb_2_0_extension_descriptor@4 = libusb_free_usb_2_0_extension_descriptor
35
45
  libusb_get_active_config_descriptor
36
46
  libusb_get_active_config_descriptor@8 = libusb_get_active_config_descriptor
47
+ libusb_get_bos_descriptor
48
+ libusb_get_bos_descriptor@8 = libusb_get_bos_descriptor
37
49
  libusb_get_bus_number
38
50
  libusb_get_bus_number@4 = libusb_get_bus_number
39
51
  libusb_get_config_descriptor
@@ -42,6 +54,8 @@ EXPORTS
42
54
  libusb_get_config_descriptor_by_value@12 = libusb_get_config_descriptor_by_value
43
55
  libusb_get_configuration
44
56
  libusb_get_configuration@8 = libusb_get_configuration
57
+ libusb_get_container_id_descriptor
58
+ libusb_get_container_id_descriptor@12 = libusb_get_container_id_descriptor
45
59
  libusb_get_device
46
60
  libusb_get_device@4 = libusb_get_device
47
61
  libusb_get_device_address
@@ -64,10 +78,18 @@ EXPORTS
64
78
  libusb_get_pollfds@4 = libusb_get_pollfds
65
79
  libusb_get_port_number
66
80
  libusb_get_port_number@4 = libusb_get_port_number
81
+ libusb_get_port_numbers
82
+ libusb_get_port_numbers@12 = libusb_get_port_numbers
67
83
  libusb_get_port_path
68
84
  libusb_get_port_path@16 = libusb_get_port_path
85
+ libusb_get_ss_endpoint_companion_descriptor
86
+ libusb_get_ss_endpoint_companion_descriptor@12 = libusb_get_ss_endpoint_companion_descriptor
87
+ libusb_get_ss_usb_device_capability_descriptor
88
+ libusb_get_ss_usb_device_capability_descriptor@12 = libusb_get_ss_usb_device_capability_descriptor
69
89
  libusb_get_string_descriptor_ascii
70
90
  libusb_get_string_descriptor_ascii@16 = libusb_get_string_descriptor_ascii
91
+ libusb_get_usb_2_0_extension_descriptor
92
+ libusb_get_usb_2_0_extension_descriptor@12 = libusb_get_usb_2_0_extension_descriptor
71
93
  libusb_get_version
72
94
  libusb_get_version@0 = libusb_get_version
73
95
  libusb_handle_events
@@ -82,6 +104,10 @@ EXPORTS
82
104
  libusb_handle_events_timeout_completed@12 = libusb_handle_events_timeout_completed
83
105
  libusb_has_capability
84
106
  libusb_has_capability@4 = libusb_has_capability
107
+ libusb_hotplug_deregister_callback
108
+ libusb_hotplug_deregister_callback@8 = libusb_hotplug_deregister_callback
109
+ libusb_hotplug_register_callback
110
+ libusb_hotplug_register_callback@36 = libusb_hotplug_register_callback
85
111
  libusb_init
86
112
  libusb_init@4 = libusb_init
87
113
  libusb_interrupt_transfer
@@ -104,6 +130,8 @@ EXPORTS
104
130
  libusb_release_interface@8 = libusb_release_interface
105
131
  libusb_reset_device
106
132
  libusb_reset_device@4 = libusb_reset_device
133
+ libusb_set_auto_detach_kernel_driver
134
+ libusb_set_auto_detach_kernel_driver@8 = libusb_set_auto_detach_kernel_driver
107
135
  libusb_set_configuration
108
136
  libusb_set_configuration@8 = libusb_set_configuration
109
137
  libusb_set_debug
@@ -112,6 +140,10 @@ EXPORTS
112
140
  libusb_set_interface_alt_setting@12 = libusb_set_interface_alt_setting
113
141
  libusb_set_pollfd_notifiers
114
142
  libusb_set_pollfd_notifiers@16 = libusb_set_pollfd_notifiers
143
+ libusb_setlocale
144
+ libusb_setlocale@4 = libusb_setlocale
145
+ libusb_strerror
146
+ libusb_strerror@4 = libusb_strerror
115
147
  libusb_submit_transfer
116
148
  libusb_submit_transfer@4 = libusb_submit_transfer
117
149
  libusb_try_lock_events
@@ -5,7 +5,9 @@
5
5
  * The information can then be queried using standard APIs and can also be
6
6
  * viewed with utilities such as Windows Explorer.
7
7
  */
8
+ #ifndef _WIN32_WCE
8
9
  #include "winresrc.h"
10
+ #endif
9
11
 
10
12
  #include "version.h"
11
13
  #ifndef LIBUSB_VERSIONSTRING
@@ -3,6 +3,7 @@
3
3
  * Copyright © 2001 Johannes Erdfelt <johannes@erdfelt.com>
4
4
  * Copyright © 2007-2008 Daniel Drake <dsd@gentoo.org>
5
5
  * Copyright © 2012 Pete Batard <pete@akeo.ie>
6
+ * Copyright © 2012 Nathan Hjelm <hjelmn@cs.unm.edu>
6
7
  * For more information, please visit: http://libusbx.org
7
8
  *
8
9
  * This library is free software; you can redistribute it and/or
@@ -40,7 +41,7 @@
40
41
  #endif /* _SSIZE_T_DEFINED */
41
42
  #endif /* _MSC_VER */
42
43
 
43
- /* stdint.h is also not usually available on MS */
44
+ /* stdint.h is not available on older MSVC */
44
45
  #if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
45
46
  typedef unsigned __int8 uint8_t;
46
47
  typedef unsigned __int16 uint16_t;
@@ -49,26 +50,39 @@ typedef unsigned __int32 uint32_t;
49
50
  #include <stdint.h>
50
51
  #endif
51
52
 
53
+ #if !defined(_WIN32_WCE)
52
54
  #include <sys/types.h>
53
- #include <time.h>
54
- #include <limits.h>
55
+ #endif
55
56
 
56
57
  #if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__)
57
58
  #include <sys/time.h>
58
59
  #endif
59
60
 
61
+ #include <time.h>
62
+ #include <limits.h>
63
+
60
64
  /* 'interface' might be defined as a macro on Windows, so we need to
61
65
  * undefine it so as not to break the current libusbx API, because
62
66
  * libusb_config_descriptor has an 'interface' member
63
67
  * As this can be problematic if you include windows.h after libusb.h
64
68
  * in your sources, we force windows.h to be included first. */
65
- #if defined(_WIN32) || defined(__CYGWIN__)
69
+ #if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
66
70
  #include <windows.h>
67
71
  #if defined(interface)
68
72
  #undef interface
69
73
  #endif
74
+ #if !defined(__CYGWIN__)
75
+ #include <winsock.h>
76
+ #endif
70
77
  #endif
71
78
 
79
+ #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
80
+ #define LIBUSB_DEPRECATED_FOR(f) \
81
+ __attribute__((deprecated("Use " #f " instead")))
82
+ #else
83
+ #define LIBUSB_DEPRECATED_FOR(f)
84
+ #endif /* __GNUC__ */
85
+
72
86
  /** \def LIBUSB_CALL
73
87
  * \ingroup misc
74
88
  * libusbx's Windows calling convention.
@@ -101,7 +115,7 @@ typedef unsigned __int32 uint32_t;
101
115
  * return type, before the function name. See internal documentation for
102
116
  * API_EXPORTED.
103
117
  */
104
- #if defined(_WIN32) || defined(__CYGWIN__)
118
+ #if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
105
119
  #define LIBUSB_CALL WINAPI
106
120
  #else
107
121
  #define LIBUSB_CALL
@@ -130,13 +144,13 @@ typedef unsigned __int32 uint32_t;
130
144
  * Internally, LIBUSBX_API_VERSION is defined as follows:
131
145
  * (libusbx major << 24) | (libusbx minor << 16) | (16 bit incremental)
132
146
  */
133
- #define LIBUSBX_API_VERSION 0x010000FF
147
+ #define LIBUSBX_API_VERSION 0x01000102
134
148
 
135
149
  #ifdef __cplusplus
136
150
  extern "C" {
137
151
  #endif
138
152
 
139
- /** \def libusb_cpu_to_le16
153
+ /** \fn libusb_cpu_to_le16
140
154
  * \ingroup misc
141
155
  * Convert a 16-bit value from host-endian to little-endian format. On
142
156
  * little endian systems, this function does nothing. On big endian systems,
@@ -150,8 +164,8 @@ static inline uint16_t libusb_cpu_to_le16(const uint16_t x)
150
164
  uint8_t b8[2];
151
165
  uint16_t b16;
152
166
  } _tmp;
153
- _tmp.b8[1] = x >> 8;
154
- _tmp.b8[0] = x & 0xff;
167
+ _tmp.b8[1] = (uint8_t) (x >> 8);
168
+ _tmp.b8[0] = (uint8_t) (x & 0xff);
155
169
  return _tmp.b16;
156
170
  }
157
171
 
@@ -247,6 +261,12 @@ enum libusb_descriptor_type {
247
261
  /** Endpoint descriptor. See libusb_endpoint_descriptor. */
248
262
  LIBUSB_DT_ENDPOINT = 0x05,
249
263
 
264
+ /** BOS descriptor */
265
+ LIBUSB_DT_BOS = 0x0f,
266
+
267
+ /** Device Capability descriptor */
268
+ LIBUSB_DT_DEVICE_CAPABILITY = 0x10,
269
+
250
270
  /** HID descriptor */
251
271
  LIBUSB_DT_HID = 0x21,
252
272
 
@@ -260,16 +280,33 @@ enum libusb_descriptor_type {
260
280
  LIBUSB_DT_HUB = 0x29,
261
281
 
262
282
  /** SuperSpeed Hub descriptor */
263
- LIBUSB_DT_SUPERSPEED_HUB = 0x2A,
283
+ LIBUSB_DT_SUPERSPEED_HUB = 0x2a,
284
+
285
+ /** SuperSpeed Endpoint Companion descriptor */
286
+ LIBUSB_DT_SS_ENDPOINT_COMPANION = 0x30
264
287
  };
265
288
 
266
289
  /* Descriptor sizes per descriptor type */
267
290
  #define LIBUSB_DT_DEVICE_SIZE 18
268
291
  #define LIBUSB_DT_CONFIG_SIZE 9
269
292
  #define LIBUSB_DT_INTERFACE_SIZE 9
270
- #define LIBUSB_DT_ENDPOINT_SIZE 7
271
- #define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
293
+ #define LIBUSB_DT_ENDPOINT_SIZE 7
294
+ #define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
272
295
  #define LIBUSB_DT_HUB_NONVAR_SIZE 7
296
+ #define LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE 6
297
+ #define LIBUSB_DT_BOS_SIZE 5
298
+ #define LIBUSB_DT_DEVICE_CAPABILITY_SIZE 3
299
+
300
+ /* BOS descriptor sizes */
301
+ #define LIBUSB_BT_USB_2_0_EXTENSION_SIZE 7
302
+ #define LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE 10
303
+ #define LIBUSB_BT_CONTAINER_ID_SIZE 20
304
+
305
+ /* We unwrap the BOS => define its max size */
306
+ #define LIBUSB_DT_BOS_MAX_SIZE ((LIBUSB_DT_BOS_SIZE) +\
307
+ (LIBUSB_BT_USB_2_0_EXTENSION_SIZE) +\
308
+ (LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE) +\
309
+ (LIBUSB_BT_CONTAINER_ID_SIZE))
273
310
 
274
311
  #define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
275
312
  #define LIBUSB_ENDPOINT_DIR_MASK 0x80
@@ -641,6 +678,187 @@ struct libusb_config_descriptor {
641
678
  int extra_length;
642
679
  };
643
680
 
681
+ /** \ingroup desc
682
+ * A structure representing the superspeed endpoint companion
683
+ * descriptor. This descriptor is documented in section 9.6.7 of
684
+ * the USB 3.0 specification. All multiple-byte fields are represented in
685
+ * host-endian format.
686
+ */
687
+ struct libusb_ss_endpoint_companion_descriptor {
688
+
689
+ /** Size of this descriptor (in bytes) */
690
+ uint8_t bLength;
691
+
692
+ /** Descriptor type. Will have value
693
+ * \ref libusb_descriptor_type::LIBUSB_DT_SS_ENDPOINT_COMPANION in
694
+ * this context. */
695
+ uint8_t bDescriptorType;
696
+
697
+
698
+ /** The maximum number of packets the endpoint can send or
699
+ * recieve as part of a burst. */
700
+ uint8_t bMaxBurst;
701
+
702
+ /** In bulk EP: bits 4:0 represents the maximum number of
703
+ * streams the EP supports. In isochronous EP: bits 1:0
704
+ * represents the Mult - a zero based value that determines
705
+ * the maximum number of packets within a service interval */
706
+ uint8_t bmAttributes;
707
+
708
+ /** The total number of bytes this EP will transfer every
709
+ * service interval. valid only for periodic EPs. */
710
+ uint16_t wBytesPerInterval;
711
+ };
712
+
713
+ /** \ingroup desc
714
+ * A generic representation of a BOS Device Capability descriptor. It is
715
+ * advised to check bDevCapabilityType and call the matching
716
+ * libusb_get_*_descriptor function to get a structure fully matching the type.
717
+ */
718
+ struct libusb_bos_dev_capability_descriptor {
719
+ /** Size of this descriptor (in bytes) */
720
+ uint8_t bLength;
721
+ /** Descriptor type. Will have value
722
+ * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
723
+ * LIBUSB_DT_DEVICE_CAPABILITY in this context. */
724
+ uint8_t bDescriptorType;
725
+ /** Device Capability type */
726
+ uint8_t bDevCapabilityType;
727
+ /** Device Capability data (bLength - 3 bytes) */
728
+ uint8_t dev_capability_data
729
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
730
+ [] /* valid C99 code */
731
+ #else
732
+ [0] /* non-standard, but usually working code */
733
+ #endif
734
+ ;
735
+ };
736
+
737
+ /** \ingroup desc
738
+ * A structure representing the Binary Device Object Store (BOS) descriptor.
739
+ * This descriptor is documented in section 9.6.2 of the USB 3.0 specification.
740
+ * All multiple-byte fields are represented in host-endian format.
741
+ */
742
+ struct libusb_bos_descriptor {
743
+ /** Size of this descriptor (in bytes) */
744
+ uint8_t bLength;
745
+
746
+ /** Descriptor type. Will have value
747
+ * \ref libusb_descriptor_type::LIBUSB_DT_BOS LIBUSB_DT_BOS
748
+ * in this context. */
749
+ uint8_t bDescriptorType;
750
+
751
+ /** Length of this descriptor and all of its sub descriptors */
752
+ uint16_t wTotalLength;
753
+
754
+ /** The number of separate device capability descriptors in
755
+ * the BOS */
756
+ uint8_t bNumDeviceCaps;
757
+
758
+ /** bNumDeviceCap Device Capability Descriptors */
759
+ struct libusb_bos_dev_capability_descriptor *dev_capability
760
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
761
+ [] /* valid C99 code */
762
+ #else
763
+ [0] /* non-standard, but usually working code */
764
+ #endif
765
+ ;
766
+ };
767
+
768
+ /** \ingroup desc
769
+ * A structure representing the USB 2.0 Extension descriptor
770
+ * This descriptor is documented in section 9.6.2.1 of the USB 3.0 specification.
771
+ * All multiple-byte fields are represented in host-endian format.
772
+ */
773
+ struct libusb_usb_2_0_extension_descriptor {
774
+ /** Size of this descriptor (in bytes) */
775
+ uint8_t bLength;
776
+
777
+ /** Descriptor type. Will have value
778
+ * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
779
+ * LIBUSB_DT_DEVICE_CAPABILITY in this context. */
780
+ uint8_t bDescriptorType;
781
+
782
+ /** Capability type. Will have value
783
+ * \ref libusb_capability_type::LIBUSB_BT_USB_2_0_EXTENSION
784
+ * LIBUSB_BT_USB_2_0_EXTENSION in this context. */
785
+ uint8_t bDevCapabilityType;
786
+
787
+ /** Bitmap encoding of supported device level features.
788
+ * A value of one in a bit location indicates a feature is
789
+ * supported; a value of zero indicates it is not supported.
790
+ * See \ref libusb_usb_2_0_extension_attributes. */
791
+ uint32_t bmAttributes;
792
+ };
793
+
794
+ /** \ingroup desc
795
+ * A structure representing the SuperSpeed USB Device Capability descriptor
796
+ * This descriptor is documented in section 9.6.2.2 of the USB 3.0 specification.
797
+ * All multiple-byte fields are represented in host-endian format.
798
+ */
799
+ struct libusb_ss_usb_device_capability_descriptor {
800
+ /** Size of this descriptor (in bytes) */
801
+ uint8_t bLength;
802
+
803
+ /** Descriptor type. Will have value
804
+ * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
805
+ * LIBUSB_DT_DEVICE_CAPABILITY in this context. */
806
+ uint8_t bDescriptorType;
807
+
808
+ /** Capability type. Will have value
809
+ * \ref libusb_capability_type::LIBUSB_BT_SS_USB_DEVICE_CAPABILITY
810
+ * LIBUSB_BT_SS_USB_DEVICE_CAPABILITY in this context. */
811
+ uint8_t bDevCapabilityType;
812
+
813
+ /** Bitmap encoding of supported device level features.
814
+ * A value of one in a bit location indicates a feature is
815
+ * supported; a value of zero indicates it is not supported.
816
+ * See \ref libusb_ss_usb_device_capability_attributes. */
817
+ uint8_t bmAttributes;
818
+
819
+ /** Bitmap encoding of the speed supported by this device when
820
+ * operating in SuperSpeed mode. See \ref libusb_supported_speed. */
821
+ uint16_t wSpeedSupported;
822
+
823
+ /** The lowest speed at which all the functionality supported
824
+ * by the device is available to the user. For example if the
825
+ * device supports all its functionality when connected at
826
+ * full speed and above then it sets this value to 1. */
827
+ uint8_t bFunctionalitySupport;
828
+
829
+ /** U1 Device Exit Latency. */
830
+ uint8_t bU1DevExitLat;
831
+
832
+ /** U2 Device Exit Latency. */
833
+ uint16_t bU2DevExitLat;
834
+ };
835
+
836
+ /** \ingroup desc
837
+ * A structure representing the Container ID descriptor.
838
+ * This descriptor is documented in section 9.6.2.3 of the USB 3.0 specification.
839
+ * All multiple-byte fields, except UUIDs, are represented in host-endian format.
840
+ */
841
+ struct libusb_container_id_descriptor {
842
+ /** Size of this descriptor (in bytes) */
843
+ uint8_t bLength;
844
+
845
+ /** Descriptor type. Will have value
846
+ * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY
847
+ * LIBUSB_DT_DEVICE_CAPABILITY in this context. */
848
+ uint8_t bDescriptorType;
849
+
850
+ /** Capability type. Will have value
851
+ * \ref libusb_capability_type::LIBUSB_BT_CONTAINER_ID
852
+ * LIBUSB_BT_CONTAINER_ID in this context. */
853
+ uint8_t bDevCapabilityType;
854
+
855
+ /** Reserved field */
856
+ uint8_t bReserved;
857
+
858
+ /** 128 bit UUID */
859
+ uint8_t ContainerID[16];
860
+ };
861
+
644
862
  /** \ingroup asyncio
645
863
  * Setup packet for control transfers. */
646
864
  struct libusb_control_setup {
@@ -676,6 +894,7 @@ struct libusb_control_setup {
676
894
  struct libusb_context;
677
895
  struct libusb_device;
678
896
  struct libusb_device_handle;
897
+ struct libusb_hotplug_callback;
679
898
 
680
899
  /** \ingroup lib
681
900
  * Structure providing the version of the libusbx runtime
@@ -727,8 +946,8 @@ typedef struct libusb_context libusb_context;
727
946
  * Certain operations can be performed on a device, but in order to do any
728
947
  * I/O you will have to first obtain a device handle using libusb_open().
729
948
  *
730
- * Devices are reference counted with libusb_device_ref() and
731
- * libusb_device_unref(), and are freed when the reference count reaches 0.
949
+ * Devices are reference counted with libusb_ref_device() and
950
+ * libusb_unref_device(), and are freed when the reference count reaches 0.
732
951
  * New devices presented by libusb_get_device_list() have a reference count of
733
952
  * 1, and libusb_free_device_list() can optionally decrease the reference count
734
953
  * on all devices in the list. libusb_open() adds another reference which is
@@ -767,11 +986,67 @@ enum libusb_speed {
767
986
  LIBUSB_SPEED_SUPER = 4,
768
987
  };
769
988
 
989
+ /** \ingroup dev
990
+ * Supported speeds (wSpeedSupported) bitfield. Indicates what
991
+ * speeds the device supports.
992
+ */
993
+ enum libusb_supported_speed {
994
+ /** Low speed operation supported (1.5MBit/s). */
995
+ LIBUSB_LOW_SPEED_OPERATION = 1,
996
+
997
+ /** Full speed operation supported (12MBit/s). */
998
+ LIBUSB_FULL_SPEED_OPERATION = 2,
999
+
1000
+ /** High speed operation supported (480MBit/s). */
1001
+ LIBUSB_HIGH_SPEED_OPERATION = 4,
1002
+
1003
+ /** Superspeed operation supported (5000MBit/s). */
1004
+ LIBUSB_SUPER_SPEED_OPERATION = 8,
1005
+ };
1006
+
1007
+ /** \ingroup dev
1008
+ * Masks for the bits of the
1009
+ * \ref libusb_usb_2_0_extension_descriptor::bmAttributes "bmAttributes" field
1010
+ * of the USB 2.0 Extension descriptor.
1011
+ */
1012
+ enum libusb_usb_2_0_extension_attributes {
1013
+ /** Supports Link Power Management (LPM) */
1014
+ LIBUSB_BM_LPM_SUPPORT = 2,
1015
+ };
1016
+
1017
+ /** \ingroup dev
1018
+ * Masks for the bits of the
1019
+ * \ref libusb_ss_usb_device_capability_descriptor::bmAttributes "bmAttributes" field
1020
+ * field of the SuperSpeed USB Device Capability descriptor.
1021
+ */
1022
+ enum libusb_ss_usb_device_capability_attributes {
1023
+ /** Supports Latency Tolerance Messages (LTM) */
1024
+ LIBUSB_BM_LTM_SUPPORT = 2,
1025
+ };
1026
+
1027
+ /** \ingroup dev
1028
+ * USB capability types
1029
+ */
1030
+ enum libusb_bos_type {
1031
+ /** Wireless USB device capability */
1032
+ LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 1,
1033
+
1034
+ /** USB 2.0 extensions */
1035
+ LIBUSB_BT_USB_2_0_EXTENSION = 2,
1036
+
1037
+ /** SuperSpeed USB device capability */
1038
+ LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 3,
1039
+
1040
+ /** Container ID type */
1041
+ LIBUSB_BT_CONTAINER_ID = 4,
1042
+ };
1043
+
770
1044
  /** \ingroup misc
771
1045
  * Error codes. Most libusbx functions return 0 on success or one of these
772
1046
  * codes on failure.
773
- * You can call \ref libusb_error_name() to retrieve a string representation
774
- * of an error code.
1047
+ * You can call libusb_error_name() to retrieve a string representation of an
1048
+ * error code or libusb_strerror() to get an end-user suitable description of
1049
+ * an error code.
775
1050
  */
776
1051
  enum libusb_error {
777
1052
  /** Success (no error) */
@@ -813,13 +1088,16 @@ enum libusb_error {
813
1088
  /** Operation not supported or unimplemented on this platform */
814
1089
  LIBUSB_ERROR_NOT_SUPPORTED = -12,
815
1090
 
816
- /* NB! Remember to update libusb_error_name()
817
- when adding new error codes here. */
1091
+ /* NB: Remember to update LIBUSB_ERROR_COUNT below as well as the
1092
+ message strings in strerror.c when adding new error codes here. */
818
1093
 
819
1094
  /** Other error */
820
1095
  LIBUSB_ERROR_OTHER = -99,
821
1096
  };
822
1097
 
1098
+ /* Total number of error codes in enum libusb_error */
1099
+ #define LIBUSB_ERROR_COUNT 14
1100
+
823
1101
  /** \ingroup asyncio
824
1102
  * Transfer status codes */
825
1103
  enum libusb_transfer_status {
@@ -982,13 +1260,23 @@ struct libusb_transfer {
982
1260
  };
983
1261
 
984
1262
  /** \ingroup misc
985
- * Capabilities supported by this instance of libusb. Test if the loaded
986
- * library supports a given capability by calling
1263
+ * Capabilities supported by an instance of libusb on the current running
1264
+ * platform. Test if the loaded library supports a given capability by calling
987
1265
  * \ref libusb_has_capability().
988
1266
  */
989
1267
  enum libusb_capability {
990
1268
  /** The libusb_has_capability() API is available. */
991
- LIBUSB_CAP_HAS_CAPABILITY = 0,
1269
+ LIBUSB_CAP_HAS_CAPABILITY = 0x0000,
1270
+ /** Hotplug support is available on this platform. */
1271
+ LIBUSB_CAP_HAS_HOTPLUG = 0x0001,
1272
+ /** The library can access HID devices without requiring user intervention.
1273
+ * Note that before being able to actually access an HID device, you may
1274
+ * still have to call additional libusbx functions such as
1275
+ * \ref libusb_detach_kernel_driver(). */
1276
+ LIBUSB_CAP_HAS_HID_ACCESS = 0x0100,
1277
+ /** The library supports detaching of the default USB driver, using
1278
+ * \ref libusb_detach_kernel_driver(), if one is set by the OS kernel */
1279
+ LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101
992
1280
  };
993
1281
 
994
1282
  /** \ingroup lib
@@ -1015,6 +1303,8 @@ void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
1015
1303
  const struct libusb_version * LIBUSB_CALL libusb_get_version(void);
1016
1304
  int LIBUSB_CALL libusb_has_capability(uint32_t capability);
1017
1305
  const char * LIBUSB_CALL libusb_error_name(int errcode);
1306
+ int LIBUSB_CALL libusb_setlocale(const char *locale);
1307
+ const char * LIBUSB_CALL libusb_strerror(enum libusb_error errcode);
1018
1308
 
1019
1309
  ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
1020
1310
  libusb_device ***list);
@@ -1035,10 +1325,38 @@ int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,
1035
1325
  uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
1036
1326
  void LIBUSB_CALL libusb_free_config_descriptor(
1037
1327
  struct libusb_config_descriptor *config);
1328
+ int LIBUSB_CALL libusb_get_ss_endpoint_companion_descriptor(
1329
+ struct libusb_context *ctx,
1330
+ const struct libusb_endpoint_descriptor *endpoint,
1331
+ struct libusb_ss_endpoint_companion_descriptor **ep_comp);
1332
+ void LIBUSB_CALL libusb_free_ss_endpoint_companion_descriptor(
1333
+ struct libusb_ss_endpoint_companion_descriptor *ep_comp);
1334
+ int LIBUSB_CALL libusb_get_bos_descriptor(libusb_device_handle *handle,
1335
+ struct libusb_bos_descriptor **bos);
1336
+ void LIBUSB_CALL libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos);
1337
+ int LIBUSB_CALL libusb_get_usb_2_0_extension_descriptor(
1338
+ struct libusb_context *ctx,
1339
+ struct libusb_bos_dev_capability_descriptor *dev_cap,
1340
+ struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension);
1341
+ void LIBUSB_CALL libusb_free_usb_2_0_extension_descriptor(
1342
+ struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension);
1343
+ int LIBUSB_CALL libusb_get_ss_usb_device_capability_descriptor(
1344
+ struct libusb_context *ctx,
1345
+ struct libusb_bos_dev_capability_descriptor *dev_cap,
1346
+ struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_cap);
1347
+ void LIBUSB_CALL libusb_free_ss_usb_device_capability_descriptor(
1348
+ struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_cap);
1349
+ int LIBUSB_CALL libusb_get_container_id_descriptor(struct libusb_context *ctx,
1350
+ struct libusb_bos_dev_capability_descriptor *dev_cap,
1351
+ struct libusb_container_id_descriptor **container_id);
1352
+ void LIBUSB_CALL libusb_free_container_id_descriptor(
1353
+ struct libusb_container_id_descriptor *container_id);
1038
1354
  uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
1039
1355
  uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev);
1040
- libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev);
1356
+ int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t* port_numbers, int port_numbers_len);
1357
+ LIBUSB_DEPRECATED_FOR(libusb_get_port_numbers)
1041
1358
  int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length);
1359
+ libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev);
1042
1360
  uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
1043
1361
  int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
1044
1362
  int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
@@ -1072,6 +1390,8 @@ int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev,
1072
1390
  int interface_number);
1073
1391
  int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev,
1074
1392
  int interface_number);
1393
+ int LIBUSB_CALL libusb_set_auto_detach_kernel_driver(
1394
+ libusb_device_handle *dev, int enable);
1075
1395
 
1076
1396
  /* async I/O */
1077
1397
 
@@ -1108,7 +1428,7 @@ static inline unsigned char *libusb_control_transfer_get_data(
1108
1428
  static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
1109
1429
  struct libusb_transfer *transfer)
1110
1430
  {
1111
- return (struct libusb_control_setup *) transfer->buffer;
1431
+ return (struct libusb_control_setup *)(void *) transfer->buffer;
1112
1432
  }
1113
1433
 
1114
1434
  /** \ingroup asyncio
@@ -1117,6 +1437,7 @@ static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
1117
1437
  * be given in host-endian byte order.
1118
1438
  *
1119
1439
  * \param buffer buffer to output the setup packet into
1440
+ * This pointer must be aligned to at least 2 bytes boundary.
1120
1441
  * \param bmRequestType see the
1121
1442
  * \ref libusb_control_setup::bmRequestType "bmRequestType" field of
1122
1443
  * \ref libusb_control_setup
@@ -1137,7 +1458,7 @@ static inline void libusb_fill_control_setup(unsigned char *buffer,
1137
1458
  uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
1138
1459
  uint16_t wLength)
1139
1460
  {
1140
- struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
1461
+ struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer;
1141
1462
  setup->bmRequestType = bmRequestType;
1142
1463
  setup->bRequest = bRequest;
1143
1464
  setup->wValue = libusb_cpu_to_le16(wValue);
@@ -1173,6 +1494,7 @@ void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer);
1173
1494
  * \param dev_handle handle of the device that will handle the transfer
1174
1495
  * \param buffer data buffer. If provided, this function will interpret the
1175
1496
  * first 8 bytes as a setup packet and infer the transfer length from that.
1497
+ * This pointer must be aligned to at least 2 bytes boundary.
1176
1498
  * \param callback callback function to be invoked on transfer completion
1177
1499
  * \param user_data user data to pass to callback function
1178
1500
  * \param timeout timeout for the transfer in milliseconds
@@ -1182,15 +1504,15 @@ static inline void libusb_fill_control_transfer(
1182
1504
  unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
1183
1505
  unsigned int timeout)
1184
1506
  {
1185
- struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
1507
+ struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer;
1186
1508
  transfer->dev_handle = dev_handle;
1187
1509
  transfer->endpoint = 0;
1188
1510
  transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;
1189
1511
  transfer->timeout = timeout;
1190
1512
  transfer->buffer = buffer;
1191
1513
  if (setup)
1192
- transfer->length = LIBUSB_CONTROL_SETUP_SIZE
1193
- + libusb_le16_to_cpu(setup->wLength);
1514
+ transfer->length = (int) (LIBUSB_CONTROL_SETUP_SIZE
1515
+ + libusb_le16_to_cpu(setup->wLength));
1194
1516
  transfer->user_data = user_data;
1195
1517
  transfer->callback = callback;
1196
1518
  }
@@ -1325,7 +1647,7 @@ static inline unsigned char *libusb_get_iso_packet_buffer(
1325
1647
  * signed to avoid compiler warnings. FIXME for libusb-2. */
1326
1648
  if (packet > INT_MAX)
1327
1649
  return NULL;
1328
- _packet = packet;
1650
+ _packet = (int) packet;
1329
1651
 
1330
1652
  if (_packet >= transfer->num_iso_packets)
1331
1653
  return NULL;
@@ -1365,12 +1687,12 @@ static inline unsigned char *libusb_get_iso_packet_buffer_simple(
1365
1687
  * signed to avoid compiler warnings. FIXME for libusb-2. */
1366
1688
  if (packet > INT_MAX)
1367
1689
  return NULL;
1368
- _packet = packet;
1690
+ _packet = (int) packet;
1369
1691
 
1370
1692
  if (_packet >= transfer->num_iso_packets)
1371
1693
  return NULL;
1372
1694
 
1373
- return transfer->buffer + (transfer->iso_packet_desc[0].length * _packet);
1695
+ return transfer->buffer + ((int) transfer->iso_packet_desc[0].length * _packet);
1374
1696
  }
1375
1697
 
1376
1698
  /* sync I/O */
@@ -1403,8 +1725,8 @@ static inline int libusb_get_descriptor(libusb_device_handle *dev,
1403
1725
  uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length)
1404
1726
  {
1405
1727
  return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
1406
- LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data,
1407
- (uint16_t) length, 1000);
1728
+ LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t) ((desc_type << 8) | desc_index),
1729
+ 0, data, (uint16_t) length, 1000);
1408
1730
  }
1409
1731
 
1410
1732
  /** \ingroup desc
@@ -1499,6 +1821,133 @@ void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
1499
1821
  libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
1500
1822
  void *user_data);
1501
1823
 
1824
+ /** \ingroup hotplug
1825
+ * Callback handle.
1826
+ *
1827
+ * Callbacks handles are generated by libusb_hotplug_register_callback()
1828
+ * and can be used to deregister callbacks. Callback handles are unique
1829
+ * per libusb_context and it is safe to call libusb_hotplug_deregister_callback()
1830
+ * on an already deregisted callback.
1831
+ *
1832
+ * Since version 1.0.16, \ref LIBUSBX_API_VERSION >= 0x01000102
1833
+ *
1834
+ * For more information, see \ref hotplug.
1835
+ */
1836
+ typedef int libusb_hotplug_callback_handle;
1837
+
1838
+ /** \ingroup hotplug
1839
+ *
1840
+ * Since version 1.0.16, \ref LIBUSBX_API_VERSION >= 0x01000102
1841
+ *
1842
+ * Flags for hotplug events */
1843
+ typedef enum {
1844
+ /** Arm the callback and fire it for all matching currently attached devices. */
1845
+ LIBUSB_HOTPLUG_ENUMERATE = 1,
1846
+ } libusb_hotplug_flag;
1847
+
1848
+ /** \ingroup hotplug
1849
+ *
1850
+ * Since version 1.0.16, \ref LIBUSBX_API_VERSION >= 0x01000102
1851
+ *
1852
+ * Hotplug events */
1853
+ typedef enum {
1854
+ /** A device has been plugged in and is ready to use */
1855
+ LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01,
1856
+
1857
+ /** A device has left and is no longer available.
1858
+ * It is the user's responsibility to call libusb_close on any handle associated with a disconnected device.
1859
+ * It is safe to call libusb_get_device_descriptor on a device that has left */
1860
+ LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02,
1861
+ } libusb_hotplug_event;
1862
+
1863
+ /** \ingroup hotplug
1864
+ * Wildcard matching for hotplug events */
1865
+ #define LIBUSB_HOTPLUG_MATCH_ANY -1
1866
+
1867
+ /** \ingroup hotplug
1868
+ * Hotplug callback function type. When requesting hotplug event notifications,
1869
+ * you pass a pointer to a callback function of this type.
1870
+ *
1871
+ * This callback may be called by an internal event thread and as such it is
1872
+ * recommended the callback do minimal processing before returning.
1873
+ *
1874
+ * libusbx will call this function later, when a matching event had happened on
1875
+ * a matching device. See \ref hotplug for more information.
1876
+ *
1877
+ * It is safe to call either libusb_hotplug_register_callback() or
1878
+ * libusb_hotplug_deregister_callback() from within a callback function.
1879
+ *
1880
+ * Since version 1.0.16, \ref LIBUSBX_API_VERSION >= 0x01000102
1881
+ *
1882
+ * \param ctx context of this notification
1883
+ * \param device libusb_device this event occurred on
1884
+ * \param event event that occurred
1885
+ * \param user_data user data provided when this callback was registered
1886
+ * \returns bool whether this callback is finished processing events.
1887
+ * returning 1 will cause this callback to be deregistered
1888
+ */
1889
+ typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx,
1890
+ libusb_device *device,
1891
+ libusb_hotplug_event event,
1892
+ void *user_data);
1893
+
1894
+ /** \ingroup hotplug
1895
+ * Register a hotplug callback function
1896
+ *
1897
+ * Register a callback with the libusb_context. The callback will fire
1898
+ * when a matching event occurs on a matching device. The callback is
1899
+ * armed until either it is deregistered with libusb_hotplug_deregister_callback()
1900
+ * or the supplied callback returns 1 to indicate it is finished processing events.
1901
+ *
1902
+ * If the \ref LIBUSB_HOTPLUG_ENUMERATE is passed the callback will be
1903
+ * called with a \ref LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED for all devices
1904
+ * already plugged into the machine. Note that libusbx modifies its internal
1905
+ * device list from a separate thread, while calling hotplug callbacks from
1906
+ * libusb_handle_events(), so it is possible for a device to already be present
1907
+ * on, or removed from, its internal device list, while the hotplug callbacks
1908
+ * still need to be dispatched. This means that when using \ref
1909
+ * LIBUSB_HOTPLUG_ENUMERATE, your callback may be called twice for the arrival
1910
+ * of the same device, once from libusb_hotplug_register_callback() and once
1911
+ * from libusb_handle_events(); and/or your callback may be called for the
1912
+ * removal of a device for which an arrived call was never made.
1913
+ *
1914
+ * Since version 1.0.16, \ref LIBUSBX_API_VERSION >= 0x01000102
1915
+ *
1916
+ * \param[in] ctx context to register this callback with
1917
+ * \param[in] events bitwise or of events that will trigger this callback. See \ref
1918
+ * libusb_hotplug_event
1919
+ * \param[in] flags hotplug callback flags. See \ref libusb_hotplug_flag
1920
+ * \param[in] vendor_id the vendor id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY
1921
+ * \param[in] product_id the product id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY
1922
+ * \param[in] dev_class the device class to match or \ref LIBUSB_HOTPLUG_MATCH_ANY
1923
+ * \param[in] cb_fn the function to be invoked on a matching event/device
1924
+ * \param[in] user_data user data to pass to the callback function
1925
+ * \param[out] handle pointer to store the handle of the allocated callback (can be NULL)
1926
+ * \returns LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure
1927
+ */
1928
+ int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx,
1929
+ libusb_hotplug_event events,
1930
+ libusb_hotplug_flag flags,
1931
+ int vendor_id, int product_id,
1932
+ int dev_class,
1933
+ libusb_hotplug_callback_fn cb_fn,
1934
+ void *user_data,
1935
+ libusb_hotplug_callback_handle *handle);
1936
+
1937
+ /** \ingroup hotplug
1938
+ * Deregisters a hotplug callback.
1939
+ *
1940
+ * Deregister a callback from a libusb_context. This function is safe to call from within
1941
+ * a hotplug callback.
1942
+ *
1943
+ * Since version 1.0.16, \ref LIBUSBX_API_VERSION >= 0x01000102
1944
+ *
1945
+ * \param[in] ctx context this callback is registered with
1946
+ * \param[in] handle the handle of the callback to deregister
1947
+ */
1948
+ void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx,
1949
+ libusb_hotplug_callback_handle handle);
1950
+
1502
1951
  #ifdef __cplusplus
1503
1952
  }
1504
1953
  #endif