libusb 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +0 -0
  4. data/.travis.yml +3 -3
  5. data/History.md +8 -0
  6. data/README.md +1 -0
  7. data/Rakefile +14 -14
  8. data/ext/{libusb-1.0.18 → libusb-1.0.19}/AUTHORS +6 -0
  9. data/ext/{libusb-1.0.18 → libusb-1.0.19}/COPYING +0 -0
  10. data/ext/{libusb-1.0.18 → libusb-1.0.19}/ChangeLog +9 -2
  11. data/ext/{libusb-1.0.18 → libusb-1.0.19}/INSTALL +0 -0
  12. data/ext/{libusb-1.0.18 → libusb-1.0.19}/Makefile.am +0 -0
  13. data/ext/{libusb-1.0.18 → libusb-1.0.19}/Makefile.in +188 -156
  14. data/ext/{libusb-1.0.18 → libusb-1.0.19}/NEWS +0 -0
  15. data/ext/{libusb-1.0.18 → libusb-1.0.19}/PORTING +0 -0
  16. data/ext/{libusb-1.0.18 → libusb-1.0.19}/README +0 -0
  17. data/ext/{libusb-1.0.18 → libusb-1.0.19}/TODO +0 -0
  18. data/ext/{libusb-1.0.18 → libusb-1.0.19}/Xcode/common.xcconfig +10 -1
  19. data/ext/{libusb-1.0.18 → libusb-1.0.19}/Xcode/config.h +0 -0
  20. data/ext/{libusb-1.0.18 → libusb-1.0.19}/Xcode/debug.xcconfig +0 -0
  21. data/ext/{libusb-1.0.18 → libusb-1.0.19}/Xcode/libusb.xcconfig +1 -1
  22. data/ext/{libusb-1.0.18 → libusb-1.0.19}/Xcode/libusb.xcodeproj/project.pbxproj +0 -0
  23. data/ext/{libusb-1.0.18 → libusb-1.0.19}/Xcode/libusb_debug.xcconfig +0 -0
  24. data/ext/{libusb-1.0.18 → libusb-1.0.19}/Xcode/libusb_release.xcconfig +0 -0
  25. data/ext/{libusb-1.0.18 → libusb-1.0.19}/Xcode/release.xcconfig +1 -0
  26. data/ext/libusb-1.0.19/aclocal.m4 +1190 -0
  27. data/ext/{libusb-1.0.18 → libusb-1.0.19}/android/README +0 -0
  28. data/ext/{libusb-1.0.18 → libusb-1.0.19}/android/config.h +0 -0
  29. data/ext/{libusb-1.0.18 → libusb-1.0.19}/android/jni/Android.mk +0 -0
  30. data/ext/{libusb-1.0.18 → libusb-1.0.19}/android/jni/Application.mk +0 -0
  31. data/ext/{libusb-1.0.18 → libusb-1.0.19}/android/jni/examples.mk +0 -0
  32. data/ext/{libusb-1.0.18 → libusb-1.0.19}/android/jni/libusb.mk +0 -0
  33. data/ext/{libusb-1.0.18 → libusb-1.0.19}/android/jni/tests.mk +0 -0
  34. data/ext/{libusb-1.0.18 → libusb-1.0.19}/compile +7 -3
  35. data/ext/{libusb-1.0.18 → libusb-1.0.19}/config.guess +116 -78
  36. data/ext/{libusb-1.0.18 → libusb-1.0.19}/config.h.in +0 -3
  37. data/ext/{libusb-1.0.18 → libusb-1.0.19}/config.sub +66 -46
  38. data/ext/{libusb-1.0.18 → libusb-1.0.19}/configure +265 -208
  39. data/ext/{libusb-1.0.18 → libusb-1.0.19}/configure.ac +0 -0
  40. data/ext/{libusb-1.0.18 → libusb-1.0.19}/depcomp +269 -186
  41. data/ext/{libusb-1.0.18 → libusb-1.0.19}/doc/Makefile.am +0 -0
  42. data/ext/{libusb-1.0.18 → libusb-1.0.19}/doc/Makefile.in +72 -35
  43. data/ext/{libusb-1.0.18 → libusb-1.0.19}/doc/doxygen.cfg.in +1 -1
  44. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/Makefile.am +0 -0
  45. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/Makefile.in +134 -70
  46. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/dpfp.c +0 -0
  47. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/dpfp_threaded.c +0 -0
  48. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/ezusb.c +9 -5
  49. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/ezusb.h +0 -0
  50. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/fxload.c +1 -1
  51. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/getopt/getopt.c +0 -0
  52. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/getopt/getopt.h +0 -0
  53. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/getopt/getopt1.c +0 -0
  54. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/hotplugtest.c +0 -0
  55. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/listdevs.c +0 -0
  56. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/sam3u_benchmark.c +0 -0
  57. data/ext/{libusb-1.0.18 → libusb-1.0.19}/examples/xusb.c +22 -2
  58. data/ext/{libusb-1.0.18 → libusb-1.0.19}/install-sh +7 -7
  59. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb-1.0.pc.in +0 -0
  60. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/Makefile.am +0 -0
  61. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/Makefile.in +133 -93
  62. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/core.c +86 -15
  63. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/descriptor.c +0 -0
  64. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/hotplug.c +6 -1
  65. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/hotplug.h +0 -0
  66. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/io.c +54 -17
  67. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/libusb-1.0.def +8 -0
  68. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/libusb-1.0.rc +0 -0
  69. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/libusb.h +42 -2
  70. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/libusbi.h +10 -1
  71. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/darwin_usb.c +156 -53
  72. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/darwin_usb.h +1 -1
  73. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/linux_netlink.c +26 -2
  74. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/linux_udev.c +2 -1
  75. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/linux_usbfs.c +93 -6
  76. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/linux_usbfs.h +12 -1
  77. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/netbsd_usb.c +6 -0
  78. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/openbsd_usb.c +6 -0
  79. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/poll_posix.c +0 -0
  80. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/poll_posix.h +0 -0
  81. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/poll_windows.c +0 -0
  82. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/poll_windows.h +12 -6
  83. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/threads_posix.c +0 -0
  84. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/threads_posix.h +0 -0
  85. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/threads_windows.c +0 -0
  86. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/threads_windows.h +0 -0
  87. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/wince_usb.c +8 -1
  88. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/wince_usb.h +0 -0
  89. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/windows_common.h +0 -0
  90. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/windows_usb.c +175 -42
  91. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/os/windows_usb.h +35 -0
  92. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/strerror.c +17 -2
  93. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/sync.c +0 -0
  94. data/ext/{libusb-1.0.18 → libusb-1.0.19}/libusb/version.h +1 -1
  95. data/ext/libusb-1.0.19/libusb/version_nano.h +1 -0
  96. data/ext/{libusb-1.0.18 → libusb-1.0.19}/ltmain.sh +3 -3
  97. data/ext/{libusb-1.0.18/aclocal.m4 → libusb-1.0.19/m4/libtool.m4} +36 -1734
  98. data/ext/libusb-1.0.19/m4/ltoptions.m4 +384 -0
  99. data/ext/libusb-1.0.19/m4/ltsugar.m4 +123 -0
  100. data/ext/libusb-1.0.19/m4/ltversion.m4 +23 -0
  101. data/ext/libusb-1.0.19/m4/lt~obsolete.m4 +98 -0
  102. data/ext/libusb-1.0.19/missing +215 -0
  103. data/ext/{libusb-1.0.18 → libusb-1.0.19}/tests/Makefile.am +0 -0
  104. data/ext/{libusb-1.0.18 → libusb-1.0.19}/tests/Makefile.in +128 -70
  105. data/ext/{libusb-1.0.18 → libusb-1.0.19}/tests/libusb_testlib.h +0 -0
  106. data/ext/{libusb-1.0.18 → libusb-1.0.19}/tests/stress.c +0 -0
  107. data/ext/{libusb-1.0.18 → libusb-1.0.19}/tests/testlib.c +0 -0
  108. data/lib/libusb.rb +3 -1
  109. data/lib/libusb/bos.rb +306 -0
  110. data/lib/libusb/call.rb +84 -0
  111. data/lib/libusb/constants.rb +4 -0
  112. data/lib/libusb/dev_handle.rb +77 -0
  113. data/lib/libusb/endpoint.rb +20 -0
  114. data/lib/libusb/ss_companion.rb +69 -0
  115. data/lib/libusb/transfer.rb +34 -0
  116. data/lib/libusb/version_gem.rb +1 -1
  117. data/libusb.gemspec +1 -0
  118. data/test/test_libusb_bos.rb +118 -0
  119. data/test/test_libusb_bulk_stream_transfer.rb +50 -0
  120. data/test/test_libusb_descriptors.rb +29 -0
  121. data/test/test_libusb_hotplug.rb +1 -1
  122. data/test/test_libusb_threads.rb +1 -1
  123. metadata +146 -124
  124. metadata.gz.sig +0 -0
  125. data/ext/libusb-1.0.18/libusb/version_nano.h +0 -1
  126. data/ext/libusb-1.0.18/missing +0 -331
File without changes
data/lib/libusb.rb CHANGED
@@ -25,7 +25,9 @@ module LIBUSB
25
25
  autoload :Endpoint, 'libusb/endpoint'
26
26
  autoload :Interface, 'libusb/interface'
27
27
  autoload :Setting, 'libusb/setting'
28
- %w[ Transfer BulkTransfer ControlTransfer InterruptTransfer IsoPacket IsochronousTransfer ].each do |klass|
28
+ autoload :SsCompanion, 'libusb/ss_companion'
29
+ autoload :Bos, 'libusb/bos'
30
+ %w[ Transfer BulkTransfer BulkStreamTransfer ControlTransfer InterruptTransfer IsoPacket IsochronousTransfer ].each do |klass|
29
31
  autoload klass, 'libusb/transfer'
30
32
  end
31
33
 
data/lib/libusb/bos.rb ADDED
@@ -0,0 +1,306 @@
1
+ # This file is part of Libusb for Ruby.
2
+ #
3
+ # Libusb for Ruby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Lesser General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # Libusb for Ruby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with Libusb for Ruby. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require 'libusb/call'
17
+
18
+ module LIBUSB
19
+ # A structure representing the Binary Device Object Store (BOS) descriptor.
20
+ # This descriptor is documented in section 9.6.2 of the USB 3.0 specification.
21
+ # All multiple-byte fields are represented in host-endian format.
22
+ class Bos < FFI::ManagedStruct
23
+
24
+ module GenericMethods
25
+ # @return [Integer] Size of this descriptor (in bytes)
26
+ def bLength
27
+ self[:bLength]
28
+ end
29
+
30
+ # @return [Integer] Descriptor type. Will have value LIBUSB::DT_DEVICE_CAPABILITY
31
+ # in this context.
32
+ def bDescriptorType
33
+ self[:bDescriptorType]
34
+ end
35
+
36
+ # @return [Integer] Device Capability type
37
+ def bDevCapabilityType
38
+ self[:bDevCapabilityType]
39
+ end
40
+
41
+ def inspect
42
+ "\#<#{self.class} cap: #{bDevCapabilityType} data: #{dev_capability_data.unpack("H*")[0]}>"
43
+ end
44
+
45
+ # @return [String] Device Capability data (bLength - 3 bytes)
46
+ def dev_capability_data
47
+ pointer.read_bytes(bLength - 3)
48
+ end
49
+ end
50
+
51
+ # A generic representation of a BOS Device Capability descriptor.
52
+ class DeviceCapability < FFI::Struct
53
+ include GenericMethods
54
+
55
+ layout :bLength, :uint8,
56
+ :bDescriptorType, :uint8,
57
+ :bDevCapabilityType, :uint8
58
+
59
+ def initialize( bos, *args)
60
+ # Avoid that the bos struct is GC'ed before this instance
61
+ @bos = bos
62
+ super(*args)
63
+ end
64
+ end
65
+
66
+ # A structure representing the USB 2.0 Extension descriptor
67
+ # This descriptor is documented in section 9.6.2.1 of the USB 3.0 specification.
68
+ # All multiple-byte fields are represented in host-endian format.
69
+ class Usb20Extension < FFI::ManagedStruct
70
+ include GenericMethods
71
+
72
+ layout :bLength, :uint8,
73
+ :bDescriptorType, :uint8,
74
+ :bDevCapabilityType, :uint8,
75
+ :bmAttributes, :uint32
76
+
77
+ # Bitmap encoding of supported device level features.
78
+ # A value of one in a bit location indicates a feature is
79
+ # supported; a value of zero indicates it is not supported.
80
+ # @see Call::Usb20ExtensionAttributes
81
+ def bmAttributes
82
+ self[:bmAttributes]
83
+ end
84
+
85
+ # @return [Boolean] Supports Link Power Management (LPM)
86
+ def bm_lpm_support?
87
+ (bmAttributes & BM_LPM_SUPPORT) != 0
88
+ end
89
+
90
+ def inspect
91
+ attrs = Call::Usb20ExtensionAttributes.to_h.map do |k, v|
92
+ (bmAttributes & v) ? k.to_s : nil
93
+ end
94
+ "\#<#{self.class} #{attrs.compact.join(",")}>"
95
+ end
96
+
97
+ # @private
98
+ def self.release(ptr)
99
+ Call.libusb_free_usb_2_0_extension_descriptor(ptr)
100
+ end
101
+ end
102
+
103
+ # A structure representing the SuperSpeed USB Device Capability descriptor
104
+ # This descriptor is documented in section 9.6.2.2 of the USB 3.0 specification.
105
+ # All multiple-byte fields are represented in host-endian format.
106
+ class SsUsbDeviceCapability < FFI::ManagedStruct
107
+ include GenericMethods
108
+
109
+ layout :bLength, :uint8,
110
+ :bDescriptorType, :uint8,
111
+ :bDevCapabilityType, :uint8,
112
+ :bmAttributes, :uint32,
113
+ :wSpeedSupported, :uint16,
114
+ :bFunctionalitySupport, :uint8,
115
+ :bU1DevExitLat, :uint8,
116
+ :bU2DevExitLat, :uint16
117
+
118
+ # Bitmap encoding of supported device level features.
119
+ # A value of one in a bit location indicates a feature is
120
+ # supported; a value of zero indicates it is not supported.
121
+ #
122
+ # @return [Integer]
123
+ # @see Call::SsUsbDeviceCapabilityAttributes
124
+ def bmAttributes
125
+ self[:bmAttributes]
126
+ end
127
+
128
+ # @return [Boolean] Supports Latency Tolerance Messages (LTM)
129
+ def bm_ltm_support?
130
+ (bmAttributes & BM_LTM_SUPPORT) != 0
131
+ end
132
+
133
+ def inspect
134
+ attrs = Call::SsUsbDeviceCapabilityAttributes.to_h.map do |k,v|
135
+ (bmAttributes & v) != 0 ? k.to_s : nil
136
+ end
137
+ "\#<#{self.class} #{attrs.compact.join(",")} #{supported_speeds.join(",")}>"
138
+ end
139
+
140
+ # Bitmap encoding of the speed supported by this device when
141
+ # operating in SuperSpeed mode.
142
+ #
143
+ # @return [Integer]
144
+ # @see Call::SupportedSpeeds
145
+ def wSpeedSupported
146
+ self[:wSpeedSupported]
147
+ end
148
+
149
+ # @return [Array<Symbol>] speeds supported by this device when
150
+ # operating in SuperSpeed mode {Call::SupportedSpeeds}
151
+ def supported_speeds
152
+ speeds = Call::SupportedSpeeds.to_h.map do |k,v|
153
+ (wSpeedSupported & v) != 0 ? k : nil
154
+ end
155
+ speeds.compact
156
+ end
157
+
158
+ # The lowest speed at which all the functionality supported
159
+ # by the device is available to the user. For example if the
160
+ # device supports all its functionality when connected at
161
+ # full speed and above then it sets this value to 1.
162
+ #
163
+ # 0 - low speed
164
+ # 1 - full speed
165
+ # 2 - high speed
166
+ # 3 - super speed
167
+ # @return [Integer]
168
+ def bFunctionalitySupport
169
+ self[:bFunctionalitySupport]
170
+ end
171
+
172
+ # @return [Integer] U1 Device Exit Latency.
173
+ def bU1DevExitLat
174
+ self[:bU1DevExitLat]
175
+ end
176
+
177
+ # @return [Integer] U2 Device Exit Latency.
178
+ def bU2DevExitLat
179
+ self[:bU2DevExitLat]
180
+ end
181
+
182
+ # @private
183
+ def self.release(ptr)
184
+ Call.libusb_free_ss_usb_device_capability_descriptor(ptr)
185
+ end
186
+ end
187
+
188
+ # A structure representing the Container ID descriptor.
189
+ # This descriptor is documented in section 9.6.2.3 of the USB 3.0 specification.
190
+ # All multiple-byte fields, except UUIDs, are represented in host-endian format.
191
+ class ContainerId < FFI::ManagedStruct
192
+ include GenericMethods
193
+
194
+ layout :bLength, :uint8,
195
+ :bDescriptorType, :uint8,
196
+ :bDevCapabilityType, :uint8,
197
+ :bReserved, :uint8,
198
+ :ContainerID, [:uint8, 16]
199
+
200
+ # Reserved field
201
+ def bReserved
202
+ self[:bReserved]
203
+ end
204
+
205
+ # @return [String] 128 bit UUID
206
+ def container_id
207
+ self[:ContainerID].to_ptr.read_bytes(16)
208
+ end
209
+
210
+ def inspect
211
+ "\#<#{self.class} #{container_id.unpack("H*")[0]}>"
212
+ end
213
+
214
+ # @private
215
+ def self.release(ptr)
216
+ Call.libusb_free_container_id_descriptor(ptr)
217
+ end
218
+ end
219
+
220
+ def initialize( ctx, *args)
221
+ @ctx = ctx
222
+ super(*args)
223
+ end
224
+
225
+ layout :bLength, :uint8,
226
+ :bDescriptorType, :uint8,
227
+ :wTotalLength, :uint16,
228
+ :bNumDeviceCaps, :uint8,
229
+ :dev_capability, [:pointer, 0]
230
+
231
+ # @return [Integer] Size of this descriptor (in bytes)
232
+ def bLength
233
+ self[:bLength]
234
+ end
235
+
236
+ # @return [Integer] Descriptor type. Will have value LIBUSB::DT_BOS LIBUSB_DT_BOS
237
+ # in this context.
238
+ def bDescriptorType
239
+ self[:bDescriptorType]
240
+ end
241
+
242
+ # @return [Integer] Length of this descriptor and all of its sub descriptors
243
+ def wTotalLength
244
+ self[:wTotalLength]
245
+ end
246
+
247
+ # @return [Integer] The number of separate device capability descriptors in
248
+ # the BOS
249
+ def bNumDeviceCaps
250
+ self[:bNumDeviceCaps]
251
+ end
252
+
253
+ # bNumDeviceCap Device Capability Descriptors
254
+ #
255
+ # @return [Array<Bos::DeviceCapability, Bos::Usb20Extension, Bos::SsUsbDeviceCapability, Bos::ContainerId>]
256
+ def device_capabilities
257
+ pp_ext = FFI::MemoryPointer.new :pointer
258
+ caps = []
259
+ # Capabilities are appended to the bos header
260
+ ptr = pointer + offset_of(:dev_capability)
261
+ bNumDeviceCaps.times do
262
+ cap = DeviceCapability.new self, ptr.read_pointer
263
+ case cap.bDevCapabilityType
264
+ when LIBUSB::BT_WIRELESS_USB_DEVICE_CAPABILITY
265
+ # no struct defined in libusb -> use generic DeviceCapability
266
+ when LIBUSB::BT_USB_2_0_EXTENSION
267
+ res = Call.libusb_get_usb_2_0_extension_descriptor(@ctx, cap.pointer, pp_ext)
268
+ cap = Usb20Extension.new(pp_ext.read_pointer) if res==0
269
+ when LIBUSB::BT_SS_USB_DEVICE_CAPABILITY
270
+ res = Call.libusb_get_ss_usb_device_capability_descriptor(@ctx, cap.pointer, pp_ext)
271
+ cap = SsUsbDeviceCapability.new(pp_ext.read_pointer) if res==0
272
+ when LIBUSB::BT_CONTAINER_ID
273
+ res = Call.libusb_get_container_id_descriptor(@ctx, cap.pointer, pp_ext)
274
+ cap = ContainerId.new(pp_ext.read_pointer) if res==0
275
+ else
276
+ # unknown capability -> use generic DeviceCapability
277
+ end
278
+ ptr += FFI.type_size(:pointer)
279
+ caps << cap
280
+ end
281
+ caps
282
+ end
283
+
284
+ # @return [Array<Symbol>] Types of Capabilities
285
+ #
286
+ # @see Call::BosTypes
287
+ def device_capability_types
288
+ # Capabilities are appended to the bos header
289
+ ptr = pointer + offset_of(:dev_capability)
290
+ bNumDeviceCaps.times.map do
291
+ cap = DeviceCapability.new self, ptr.read_pointer
292
+ ptr += FFI.type_size(:pointer)
293
+ Call::BosTypes.find cap.bDevCapabilityType
294
+ end
295
+ end
296
+
297
+ def inspect
298
+ "\#<#{self.class} #{device_capability_types.join(", ")}>"
299
+ end
300
+
301
+ # @private
302
+ def self.release(ptr)
303
+ Call.libusb_free_bos_descriptor(ptr)
304
+ end
305
+ end
306
+ end
data/lib/libusb/call.rb CHANGED
@@ -81,11 +81,18 @@ module LIBUSB
81
81
  :TRANSFER_ADD_ZERO_PACKET, 1 << 3,
82
82
  ]
83
83
 
84
+ # Values for {Endpoint#transfer_type}.
84
85
  TransferTypes = enum :libusb_transfer_type, [
86
+ # Control endpoint
85
87
  :TRANSFER_TYPE_CONTROL, 0,
88
+ # Isochronous endpoint
86
89
  :TRANSFER_TYPE_ISOCHRONOUS, 1,
90
+ # Bulk endpoint
87
91
  :TRANSFER_TYPE_BULK, 2,
92
+ # Interrupt endpoint
88
93
  :TRANSFER_TYPE_INTERRUPT, 3,
94
+ # Stream endpoint
95
+ :TRANSFER_TYPE_BULK_STREAM, 4,
89
96
  ]
90
97
 
91
98
  StandardRequests = enum :libusb_standard_request, [
@@ -108,15 +115,32 @@ module LIBUSB
108
115
  ]
109
116
 
110
117
  DescriptorTypes = enum :libusb_descriptor_type, [
118
+ # Device descriptor. See {Device}
111
119
  :DT_DEVICE, 0x01,
120
+ # Configuration descriptor. See {Configuration}
112
121
  :DT_CONFIG, 0x02,
122
+ # String descriptor
113
123
  :DT_STRING, 0x03,
124
+ # Interface descriptor. See {Interface}
114
125
  :DT_INTERFACE, 0x04,
126
+ # Endpoint descriptor. See {Endpoint}
115
127
  :DT_ENDPOINT, 0x05,
128
+ # BOS descriptor
129
+ :DT_BOS, 0x0f,
130
+ # Device Capability descriptor
131
+ :DT_DEVICE_CAPABILITY, 0x10,
132
+ # HID descriptor
116
133
  :DT_HID, 0x21,
134
+ # HID report descriptor
117
135
  :DT_REPORT, 0x22,
136
+ # Physical descriptor
118
137
  :DT_PHYSICAL, 0x23,
138
+ # Hub descriptor
119
139
  :DT_HUB, 0x29,
140
+ # SuperSpeed Hub descriptor
141
+ :DT_SUPERSPEED_HUB, 0x2a,
142
+ # SuperSpeed Endpoint Companion descriptor
143
+ :DT_SS_ENDPOINT_COMPANION, 0x30,
120
144
  ]
121
145
 
122
146
  RequestTypes = enum :libusb_request_type, [
@@ -148,6 +172,19 @@ module LIBUSB
148
172
  :SPEED_SUPER, 4,
149
173
  ]
150
174
 
175
+ # Supported speeds (wSpeedSupported) bitfield. Indicates what
176
+ # speeds the device supports.
177
+ SupportedSpeeds = enum :libusb_supported_speed, [
178
+ # Low speed operation supported (1.5MBit/s).
179
+ :LOW_SPEED_OPERATION, 1,
180
+ # Full speed operation supported (12MBit/s).
181
+ :FULL_SPEED_OPERATION, 2,
182
+ # High speed operation supported (480MBit/s).
183
+ :HIGH_SPEED_OPERATION, 4,
184
+ # Superspeed operation supported (5000MBit/s).
185
+ :SUPER_SPEED_OPERATION, 8,
186
+ ]
187
+
151
188
  Capabilities = enum :libusb_capability, [
152
189
  :CAP_HAS_CAPABILITY, 0x0000,
153
190
  # Hotplug support is available on this platform.
@@ -162,6 +199,36 @@ module LIBUSB
162
199
  :CAP_SUPPORTS_DETACH_KERNEL_DRIVER, 0x0101,
163
200
  ]
164
201
 
202
+ # Masks for the bits of the
203
+ # {Bos::Usb20Extension#bmAttributes} field
204
+ # of the USB 2.0 Extension descriptor.
205
+ Usb20ExtensionAttributes = enum :libusb_usb_2_0_extension_attributes, [
206
+ # Supports Link Power Management (LPM)
207
+ :BM_LPM_SUPPORT, 2,
208
+ ]
209
+
210
+ # Masks for the bits of the
211
+ # {Bos::SsUsbDeviceCapability#bmAttributes} field
212
+ # field of the SuperSpeed USB Device Capability descriptor.
213
+ SsUsbDeviceCapabilityAttributes = enum :libusb_ss_usb_device_capability_attributes, [
214
+ # Supports Latency Tolerance Messages (LTM)
215
+ :BM_LTM_SUPPORT, 2,
216
+ ]
217
+
218
+ # USB capability types
219
+ #
220
+ # @see Bos::DeviceCapability
221
+ BosTypes = enum :libusb_bos_type, [
222
+ # Wireless USB device capability
223
+ :BT_WIRELESS_USB_DEVICE_CAPABILITY, 1,
224
+ # USB 2.0 extensions
225
+ :BT_USB_2_0_EXTENSION, 2,
226
+ # SuperSpeed USB device capability
227
+ :BT_SS_USB_DEVICE_CAPABILITY, 3,
228
+ # Container ID type
229
+ :BT_CONTAINER_ID, 4,
230
+ ]
231
+
165
232
  # Since libusb version 1.0.16.
166
233
  #
167
234
  # Hotplug events
@@ -186,6 +253,7 @@ module LIBUSB
186
253
  typedef :pointer, :libusb_context
187
254
  typedef :pointer, :libusb_device
188
255
  typedef :pointer, :libusb_device_handle
256
+ typedef :pointer, :libusb_transfer
189
257
  typedef :int, :libusb_hotplug_callback_handle
190
258
 
191
259
  def self.try_attach_function(method, *args)
@@ -221,6 +289,18 @@ module LIBUSB
221
289
  attach_function 'libusb_get_max_packet_size', [:pointer, :uint8], :int
222
290
  attach_function 'libusb_get_max_iso_packet_size', [:pointer, :uint8], :int
223
291
 
292
+ try_attach_function 'libusb_get_ss_endpoint_companion_descriptor', [:pointer, :pointer, :pointer], :int
293
+ try_attach_function 'libusb_free_ss_endpoint_companion_descriptor', [:pointer], :void
294
+
295
+ try_attach_function 'libusb_get_bos_descriptor', [:libusb_device_handle, :pointer], :int, :blocking=>true
296
+ try_attach_function 'libusb_free_bos_descriptor', [:pointer], :void
297
+ try_attach_function 'libusb_get_usb_2_0_extension_descriptor', [:libusb_context, :pointer, :pointer], :int
298
+ try_attach_function 'libusb_free_usb_2_0_extension_descriptor', [:pointer], :void
299
+ try_attach_function 'libusb_get_ss_usb_device_capability_descriptor', [:libusb_context, :pointer, :pointer], :int
300
+ try_attach_function 'libusb_free_ss_usb_device_capability_descriptor', [:pointer], :void
301
+ try_attach_function 'libusb_get_container_id_descriptor', [:libusb_context, :pointer, :pointer], :int
302
+ try_attach_function 'libusb_free_container_id_descriptor', [:pointer], :void
303
+
224
304
  attach_function 'libusb_open', [:pointer, :pointer], :int
225
305
  attach_function 'libusb_close', [:pointer], :void
226
306
  attach_function 'libusb_get_device', [:libusb_device_handle], :pointer
@@ -234,6 +314,8 @@ module LIBUSB
234
314
  attach_function 'libusb_set_interface_alt_setting', [:libusb_device_handle, :int, :int], :int, :blocking=>true
235
315
  attach_function 'libusb_clear_halt', [:libusb_device_handle, :int], :int, :blocking=>true
236
316
  attach_function 'libusb_reset_device', [:libusb_device_handle], :int, :blocking=>true
317
+ try_attach_function 'libusb_alloc_streams', [:libusb_device_handle, :uint32, :pointer, :int], :int
318
+ try_attach_function 'libusb_free_streams', [:libusb_device_handle, :pointer, :int], :int
237
319
 
238
320
  attach_function 'libusb_kernel_driver_active', [:libusb_device_handle, :int], :int
239
321
  attach_function 'libusb_detach_kernel_driver', [:libusb_device_handle, :int], :int
@@ -246,6 +328,8 @@ module LIBUSB
246
328
  attach_function 'libusb_submit_transfer', [:pointer], :int
247
329
  attach_function 'libusb_cancel_transfer', [:pointer], :int
248
330
  attach_function 'libusb_free_transfer', [:pointer], :void
331
+ try_attach_function 'libusb_transfer_set_stream_id', [:libusb_transfer, :uint32], :void
332
+ try_attach_function 'libusb_transfer_get_stream_id', [:libusb_transfer], :uint32
249
333
 
250
334
  attach_function 'libusb_handle_events', [:libusb_context], :int, :blocking=>true
251
335
  try_attach_function 'libusb_handle_events_completed', [:libusb_context, :pointer], :int, :blocking=>true