libusb 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -26,6 +26,10 @@ module LIBUSB
26
26
  Call::IsoSyncTypes.to_h.each{|k,v| const_set(k,v) }
27
27
  Call::Speeds.to_h.each{|k,v| const_set(k,v) }
28
28
  Call::Capabilities.to_h.each{|k,v| const_set(k,v) }
29
+ Call::SupportedSpeeds.to_h.each{|k,v| const_set(k,v) }
30
+ Call::Usb20ExtensionAttributes.to_h.each{|k,v| const_set(k,v) }
31
+ Call::SsUsbDeviceCapabilityAttributes.to_h.each{|k,v| const_set(k,v) }
32
+ Call::BosTypes.to_h.each{|k,v| const_set(k,v) }
29
33
  Call::HotplugEvents.to_h.each{|k,v| const_set(k,v) }
30
34
  Call::HotplugFlags.to_h.each{|k,v| const_set(k,v) }
31
35
 
@@ -189,6 +189,54 @@ module LIBUSB
189
189
  LIBUSB.raise_error res, "in libusb_reset_device" if res!=0
190
190
  end
191
191
 
192
+ if Call.respond_to?(:libusb_alloc_streams)
193
+
194
+ # @method alloc_streams
195
+ #
196
+ # Allocate up to num_streams usb bulk streams on the specified endpoints. This
197
+ # function takes an array of endpoints rather then a single endpoint because
198
+ # some protocols require that endpoints are setup with similar stream ids.
199
+ # All endpoints passed in must belong to the same interface.
200
+ #
201
+ # Note this function may return less streams then requested. Also note that the
202
+ # same number of streams are allocated for each endpoint in the endpoint array.
203
+ #
204
+ # Stream id 0 is reserved, and should not be used to communicate with devices.
205
+ # If {alloc_streams} returns with a value of N, you may use stream ids
206
+ # 1 to N.
207
+ #
208
+ # Available since libusb-1.0.19.
209
+ #
210
+ # @param [Fixnum] num_streams number of streams to try to allocate
211
+ # @param [Array<Fixnum>, Array<Endpoint>] endpoints array of endpoints to allocate streams on
212
+ # @return [Fixnum] number of streams allocated
213
+ # @see #free_streams
214
+ # @see BulkStreamTransfer
215
+ def alloc_streams(num_streams, endpoints)
216
+ pEndpoints = endpoints_as_ffi_bytes(endpoints)
217
+ res = Call.libusb_alloc_streams(@pHandle, num_streams, pEndpoints, endpoints.length)
218
+ LIBUSB.raise_error res, "in libusb_alloc_streams" unless res>=0
219
+ res
220
+ end
221
+
222
+ # @method free_streams
223
+ #
224
+ # Free usb bulk streams allocated with {alloc_streams}
225
+ #
226
+ # Note streams are automatically free-ed when releasing an interface.
227
+ #
228
+ # Available since libusb-1.0.19.
229
+ #
230
+ # @param [Array<Fixnum>, Array<Endpoint>] endpoints array of endpoints to free streams on
231
+ # @see #alloc_streams
232
+ def free_streams(endpoints)
233
+ pEndpoints = endpoints_as_ffi_bytes(endpoints)
234
+ res = Call.libusb_free_streams(@pHandle, pEndpoints, endpoints.length)
235
+ LIBUSB.raise_error res, "in libusb_free_streams" unless res>=0
236
+ nil
237
+ end
238
+ end
239
+
192
240
  # Determine if a kernel driver is active on an interface.
193
241
  #
194
242
  # If a kernel driver is active, you cannot claim the interface,
@@ -253,6 +301,26 @@ module LIBUSB
253
301
  end
254
302
  end
255
303
 
304
+ # @private
305
+ if Call.respond_to?(:libusb_get_bos_descriptor)
306
+
307
+ # @method bos
308
+ # Get a Binary Object Store (BOS) descriptor.
309
+ #
310
+ # This is a BLOCKING function, which will send requests to the device.
311
+ #
312
+ # Since libusb version 1.0.16.
313
+ #
314
+ # @return [Bos]
315
+ def bos
316
+ ctx = device.context.instance_variable_get(:@ctx)
317
+ pp_desc = FFI::MemoryPointer.new :pointer
318
+ res = Call.libusb_get_bos_descriptor(@pHandle, pp_desc)
319
+ LIBUSB.raise_error res, "in libusb_get_bos_descriptor" if res!=0
320
+ Bos.new(ctx, pp_desc.read_pointer)
321
+ end
322
+ end
323
+
256
324
  # Perform a USB bulk transfer.
257
325
  #
258
326
  # When called without a block, the transfer is done synchronously - so all events are handled
@@ -473,5 +541,14 @@ module LIBUSB
473
541
  res
474
542
  end
475
543
  end
544
+
545
+ def endpoints_as_ffi_bytes(endpoints)
546
+ pEndpoints = FFI::MemoryPointer.new :char, endpoints.length
547
+ endpoints.each_with_index do |ep, epi|
548
+ ep = ep.bEndpointAddress if ep.respond_to? :bEndpointAddress
549
+ pEndpoints.put_uchar(epi, ep)
550
+ end
551
+ pEndpoints
552
+ end
476
553
  end
477
554
  end
@@ -170,5 +170,25 @@ module LIBUSB
170
170
  t = bEndpointAddress<=>o.bEndpointAddress if t==0
171
171
  t
172
172
  end
173
+
174
+ if Call.respond_to?(:libusb_get_ss_endpoint_companion_descriptor)
175
+
176
+ # @method ss_companion
177
+ # Get the endpoints superspeed endpoint companion descriptor (if any).
178
+ #
179
+ # Since libusb version 1.0.16.
180
+ #
181
+ # @return [SsCompanion]
182
+ def ss_companion
183
+ ep_comp = FFI::MemoryPointer.new :pointer
184
+ res = Call.libusb_get_ss_endpoint_companion_descriptor(
185
+ device.context.instance_variable_get(:@ctx),
186
+ pointer,
187
+ ep_comp
188
+ )
189
+ LIBUSB.raise_error res, "in libusb_get_ss_endpoint_companion_descriptor" if res!=0
190
+ SsCompanion.new ep_comp.read_pointer
191
+ end
192
+ end
173
193
  end
174
194
  end
@@ -0,0 +1,69 @@
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 superspeed endpoint companion descriptor.
20
+ #
21
+ # 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.
22
+ class SsCompanion < FFI::ManagedStruct
23
+ layout :bLength, :uint8,
24
+ :bDescriptorType, :uint8,
25
+ :bMaxBurst, :uint8,
26
+ :bmAttributes, :uint8,
27
+ :wBytesPerInterval, :uint16
28
+
29
+ # Size of this descriptor (in bytes)
30
+ def bLength
31
+ self[:bLength]
32
+ end
33
+
34
+ # Descriptor type.
35
+ #
36
+ # Will have value LIBUSB::DT_SS_ENDPOINT_COMPANION in this context.
37
+ def bDescriptorType
38
+ self[:bDescriptorType]
39
+ end
40
+
41
+ # The maximum number of packets the endpoint can send or recieve as part of a burst.
42
+ def bMaxBurst
43
+ self[:bMaxBurst]
44
+ end
45
+
46
+ # In bulk EP: bits 4:0 represents the maximum number of streams the EP supports.
47
+ #
48
+ # In isochronous EP: bits 1:0 represents the Mult - a zero based value that determines the maximum number of packets within a service interval
49
+ def bmAttributes
50
+ self[:bmAttributes]
51
+ end
52
+
53
+ # The total number of bytes this EP will transfer every service interval.
54
+ #
55
+ # valid only for periodic EPs.
56
+ def wBytesPerInterval
57
+ self[:wBytesPerInterval]
58
+ end
59
+
60
+ def inspect
61
+ "\#<#{self.class} burst: #{bMaxBurst} attrs: #{bmAttributes}>"
62
+ end
63
+
64
+ # @private
65
+ def self.release(ptr)
66
+ Call.libusb_free_ss_endpoint_companion_descriptor(ptr)
67
+ end
68
+ end
69
+ end
@@ -203,6 +203,40 @@ module LIBUSB
203
203
  end
204
204
  end
205
205
 
206
+ if Call.respond_to?(:libusb_transfer_get_stream_id)
207
+
208
+ # Transfer class for USB bulk transfers using USB-3.0 streams.
209
+ #
210
+ # @see DevHandle#alloc_streams
211
+ #
212
+ # Available since libusb-1.0.19.
213
+ class BulkStreamTransfer < Transfer
214
+ def initialize(args={})
215
+ @transfer = Call::Transfer.new Call.libusb_alloc_transfer(0)
216
+ @transfer[:type] = TRANSFER_TYPE_BULK_STREAM
217
+ @transfer[:timeout] = 1000
218
+ super
219
+ end
220
+
221
+ # Set a transfers bulk stream id.
222
+ #
223
+ # @param [Fixnum] stream_id the stream id to set
224
+ def stream_id=(v)
225
+ Call.libusb_transfer_set_stream_id(@transfer, v)
226
+ v
227
+ end
228
+
229
+ # Get a transfers bulk stream id.
230
+ #
231
+ # Since version 1.0.19.
232
+ #
233
+ # @return [Fixnum] the stream id for the transfer
234
+ def stream_id
235
+ Call.libusb_transfer_get_stream_id(@transfer)
236
+ end
237
+ end
238
+ end
239
+
206
240
  class ControlTransfer < Transfer
207
241
  def initialize(args={})
208
242
  @transfer = Call::Transfer.new Call.libusb_alloc_transfer(0)
@@ -15,5 +15,5 @@
15
15
 
16
16
  module LIBUSB
17
17
  # Library version of libusb for Ruby
18
- VERSION = "0.4.1"
18
+ VERSION = "0.5.0"
19
19
  end
data/libusb.gemspec CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.homepage = "http://github.com/larskanis/libusb"
11
11
  s.summary = %q{Access USB devices from Ruby via libusb-1.0}
12
12
  s.description = %q{LIBUSB is a Ruby binding that gives Ruby programmers access to arbitrary USB devices}
13
+ s.licenses = ['LGPL-3']
13
14
  s.rdoc_options = %w[--main README.md --charset=UTF-8]
14
15
 
15
16
  s.rubyforge_project = "libusb"
@@ -0,0 +1,118 @@
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 "minitest/autorun"
17
+ require "libusb"
18
+
19
+ class TestLibusbBos < Minitest::Test
20
+ include LIBUSB
21
+
22
+ attr_accessor :usb
23
+
24
+ def setup
25
+ @usb = Context.new
26
+ @usb.debug = 0
27
+ end
28
+
29
+ def test_bos
30
+ did_bos = false
31
+ did_cap = false
32
+ usb.devices.each do |dev|
33
+ # devices with USB version >= 0x201 could support bos
34
+ # devices with USB version >= 0x210 must support bos
35
+ if dev.bcdUSB >= 0x210
36
+ dev.open do |devh|
37
+ bos = devh.bos
38
+ did_bos = true
39
+
40
+ assert_equal 5, bos.bLength
41
+ assert_equal 0x0f, bos.bDescriptorType
42
+ assert_operator 5, :<=, bos.wTotalLength
43
+ assert_operator 0, :<=, bos.bNumDeviceCaps
44
+
45
+ caps = bos.device_capabilities
46
+ assert_equal bos.bNumDeviceCaps, caps.length
47
+ cap_types = bos.device_capability_types
48
+ assert_equal bos.bNumDeviceCaps, cap_types.length
49
+
50
+ cap_types.each do |cap_type|
51
+ assert_operator [
52
+ :BT_WIRELESS_USB_DEVICE_CAPABILITY,
53
+ :BT_USB_2_0_EXTENSION,
54
+ :BT_SS_USB_DEVICE_CAPABILITY,
55
+ :BT_CONTAINER_ID,
56
+ ], :include?, cap_type
57
+ end
58
+
59
+
60
+ caps.each do |cap|
61
+ did_cap = true
62
+
63
+ assert_operator 4, :<=, cap.bLength
64
+ assert_equal LIBUSB::DT_DEVICE_CAPABILITY, cap.bDescriptorType
65
+ assert_kind_of String, cap.dev_capability_data, "should provide binary capability data"
66
+ assert_kind_of String, cap.inspect, "should respond to inspect"
67
+ assert_operator 1, :<=, cap.dev_capability_data.length, "dev_capability_data should be at least one byte"
68
+
69
+ case cap
70
+ when Bos::DeviceCapability
71
+ assert_kind_of Integer, cap.bDevCapabilityType
72
+
73
+ when Bos::Usb20Extension
74
+ assert_equal 2, cap.bDevCapabilityType
75
+ assert_operator 0, :<=, cap.bmAttributes
76
+ assert_operator [true, false], :include?, cap.bm_lpm_support?
77
+
78
+ when Bos::SsUsbDeviceCapability
79
+ assert_equal 3, cap.bDevCapabilityType
80
+ assert_operator 0, :<=, cap.bmAttributes
81
+ assert_operator [true, false], :include?, cap.bm_ltm_support?
82
+ assert_operator 0, :<=, cap.wSpeedSupported
83
+ assert_kind_of Array, cap.supported_speeds
84
+ assert_operator 0, :<=, cap.bFunctionalitySupport
85
+ assert_operator 0, :<=, cap.bU1DevExitLat
86
+ assert_operator 0, :<=, cap.bU2DevExitLat
87
+
88
+ when Bos::ContainerId
89
+ assert_equal 4, cap.bDevCapabilityType
90
+ assert_operator 0, :<=, cap.bReserved
91
+ assert_operator 16, :==, cap.container_id.bytesize, "container_id should be 16 bytes long"
92
+
93
+ else
94
+ refute true, "invalid device capability class"
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ skip "no device with BOS available" unless did_bos
101
+ skip "no device with BOS capability available" unless did_cap
102
+ end
103
+
104
+ def test_no_bos
105
+ did_failing_bos = false
106
+
107
+ # devices with USB version < 0x201 shouldn't support bos
108
+ if dev=usb.devices.find{|dev| dev.bcdUSB < 0x201 }
109
+ dev.open do |devh|
110
+ assert_raises LIBUSB::ERROR_PIPE do
111
+ devh.bos
112
+ end
113
+ did_failing_bos = true
114
+ end
115
+ end
116
+ skip "no device without BOS available" unless did_failing_bos
117
+ end
118
+ end
@@ -0,0 +1,50 @@
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 "minitest/autorun"
17
+ require "libusb"
18
+
19
+ class TestLibusbBulkStreamTransfer < Minitest::Test
20
+ include LIBUSB
21
+
22
+ def setup
23
+ c = Context.new
24
+ begin
25
+ @dev = c.devices.first.open
26
+ rescue LIBUSB::ERROR_ACCESS
27
+ @dev = nil
28
+ skip "error opening device"
29
+ end
30
+ end
31
+
32
+ def teardown
33
+ @dev.close if @dev
34
+ end
35
+
36
+ def test_alloc_streams
37
+ assert_raises(ERROR_NOT_SUPPORTED, "TODO: test with a OS that supports bulk streams and against a real device") do
38
+ nr_allocated = @dev.alloc_streams( 2, @dev.device.endpoints )
39
+ end
40
+
41
+ assert_raises(ERROR_NOT_SUPPORTED) do
42
+ @dev.free_streams( [0x01,0x82] )
43
+ end
44
+ end
45
+
46
+ def test_bulk_stream_transfer
47
+ tr = BulkStreamTransfer.new :dev_handle=>@dev, :stream_id=>123, :buffer=>' '*100
48
+ assert_equal 123, tr.stream_id, "stream_id should match"
49
+ end
50
+ end
@@ -113,6 +113,35 @@ class TestLibusbDescriptors < Minitest::Test
113
113
  end
114
114
  end
115
115
 
116
+ def test_ss_companion
117
+ did_cc_companion = false
118
+ did_failing_cc_companion = false
119
+
120
+ usb.devices.each do |dev|
121
+ dev.endpoints.each do |ep|
122
+ if dev.device_speed == :SPEED_SUPER
123
+ ss = ep.ss_companion
124
+ assert_match(/SsCompanion/, ss.inspect, "SsCompanion#inspect should work")
125
+
126
+ assert_kind_of Integer, ss.bLength
127
+ assert_equal LIBUSB::DT_SS_ENDPOINT_COMPANION, ss.bDescriptorType
128
+ assert_kind_of Integer, ss.bMaxBurst
129
+ assert_kind_of Integer, ss.bmAttributes
130
+ assert_kind_of Integer, ss.wBytesPerInterval
131
+ did_cc_companion = true
132
+ elsif !did_failing_cc_companion
133
+ assert_raises ERROR_NOT_FOUND do
134
+ ep.ss_companion
135
+ end
136
+ did_failing_cc_companion = true
137
+ end
138
+ end
139
+ end
140
+
141
+ skip "no device with cc_companion available" unless did_cc_companion
142
+ skip "no device without cc_companion available" unless did_failing_cc_companion
143
+ end
144
+
116
145
  def test_constants
117
146
  assert_equal 7, CLASS_PRINTER, "Printer class id should be defined"
118
147
  assert_equal 48, ISO_USAGE_TYPE_MASK, "iso usage type should be defined"