libusb 0.7.0-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.appveyor.yml +33 -0
  3. data/.github/workflows/ci.yml +185 -0
  4. data/.gitignore +9 -0
  5. data/.travis.yml +26 -0
  6. data/.yardopts +6 -0
  7. data/COPYING +165 -0
  8. data/Gemfile +19 -0
  9. data/History.md +193 -0
  10. data/README.md +184 -0
  11. data/Rakefile +79 -0
  12. data/lib/libusb/bos.rb +362 -0
  13. data/lib/libusb/call.rb +622 -0
  14. data/lib/libusb/compat.rb +376 -0
  15. data/lib/libusb/configuration.rb +154 -0
  16. data/lib/libusb/constants.rb +170 -0
  17. data/lib/libusb/context.rb +576 -0
  18. data/lib/libusb/context_reference.rb +38 -0
  19. data/lib/libusb/dependencies.rb +7 -0
  20. data/lib/libusb/dev_handle.rb +574 -0
  21. data/lib/libusb/device.rb +407 -0
  22. data/lib/libusb/endpoint.rb +195 -0
  23. data/lib/libusb/eventmachine.rb +187 -0
  24. data/lib/libusb/gem_helper.rb +151 -0
  25. data/lib/libusb/interface.rb +60 -0
  26. data/lib/libusb/libusb_recipe.rb +29 -0
  27. data/lib/libusb/setting.rb +132 -0
  28. data/lib/libusb/ss_companion.rb +72 -0
  29. data/lib/libusb/stdio.rb +25 -0
  30. data/lib/libusb/transfer.rb +418 -0
  31. data/lib/libusb/version_gem.rb +19 -0
  32. data/lib/libusb/version_struct.rb +63 -0
  33. data/lib/libusb-1.0.dll +0 -0
  34. data/lib/libusb.rb +146 -0
  35. data/libusb.gemspec +28 -0
  36. data/test/test_libusb.rb +42 -0
  37. data/test/test_libusb_bos.rb +140 -0
  38. data/test/test_libusb_bulk_stream_transfer.rb +61 -0
  39. data/test/test_libusb_compat.rb +78 -0
  40. data/test/test_libusb_compat_mass_storage.rb +81 -0
  41. data/test/test_libusb_context.rb +88 -0
  42. data/test/test_libusb_descriptors.rb +245 -0
  43. data/test/test_libusb_event_machine.rb +118 -0
  44. data/test/test_libusb_gc.rb +52 -0
  45. data/test/test_libusb_hotplug.rb +129 -0
  46. data/test/test_libusb_iso_transfer.rb +56 -0
  47. data/test/test_libusb_mass_storage.rb +268 -0
  48. data/test/test_libusb_mass_storage2.rb +96 -0
  49. data/test/test_libusb_structs.rb +87 -0
  50. data/test/test_libusb_threads.rb +89 -0
  51. data/wireshark-usb-sniffer.png +0 -0
  52. metadata +112 -0
@@ -0,0 +1,622 @@
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 'rubygems'
17
+ require 'ffi'
18
+
19
+ module LIBUSB
20
+ # C level interface - for internal use only
21
+ #
22
+ # All enum codes are available as constants in {LIBUSB} namespace.
23
+ module Call
24
+ extend FFI::Library
25
+
26
+ root_path = File.expand_path("../../..", __FILE__)
27
+ ext = FFI::Platform::LIBSUFFIX
28
+ prefix = FFI::Platform::LIBPREFIX.empty? ? 'lib' : FFI::Platform::LIBPREFIX
29
+ bundled_dll = File.join(root_path, "lib/#{prefix}usb-1.0.#{ext}")
30
+ bundled_dll_cygwin = File.join(root_path, "bin/#{prefix}usb-1.0.#{ext}")
31
+ ffi_lib([bundled_dll, bundled_dll_cygwin, "#{prefix}usb-1.0.#{ext}.0", "#{prefix}usb-1.0", "#{prefix}usb"])
32
+
33
+ ClassCodes = enum :libusb_class_code, [
34
+ :CLASS_PER_INTERFACE, 0,
35
+ :CLASS_AUDIO, 1,
36
+ :CLASS_COMM, 2,
37
+ :CLASS_HID, 3,
38
+ :CLASS_PRINTER, 7,
39
+ :CLASS_PTP, 6,
40
+ :CLASS_MASS_STORAGE, 8,
41
+ :CLASS_HUB, 9,
42
+ :CLASS_DATA, 10,
43
+ :CLASS_WIRELESS, 0xe0,
44
+ :CLASS_APPLICATION, 0xfe,
45
+ :CLASS_VENDOR_SPEC, 0xff
46
+ ]
47
+
48
+ Errors = enum :libusb_error, [
49
+ :SUCCESS, 0,
50
+ :ERROR_IO, -1,
51
+ :ERROR_INVALID_PARAM, -2,
52
+ :ERROR_ACCESS, -3,
53
+ :ERROR_NO_DEVICE, -4,
54
+ :ERROR_NOT_FOUND, -5,
55
+ :ERROR_BUSY, -6,
56
+ :ERROR_TIMEOUT, -7,
57
+ :ERROR_OVERFLOW, -8,
58
+ :ERROR_PIPE, -9,
59
+ :ERROR_INTERRUPTED, -10,
60
+ :ERROR_NO_MEM, -11,
61
+ :ERROR_NOT_SUPPORTED, -12,
62
+ :ERROR_OTHER, -99,
63
+ ]
64
+
65
+ # Transfer status codes
66
+ TransferStatus = enum :libusb_transfer_status, [
67
+ :TRANSFER_COMPLETED,
68
+ :TRANSFER_ERROR,
69
+ :TRANSFER_TIMED_OUT,
70
+ :TRANSFER_CANCELLED,
71
+ :TRANSFER_STALL,
72
+ :TRANSFER_NO_DEVICE,
73
+ :TRANSFER_OVERFLOW,
74
+ ]
75
+
76
+ # libusb_transfer.flags values
77
+ TransferFlags = enum :libusb_transfer_flags, [
78
+ :TRANSFER_SHORT_NOT_OK, 1 << 0,
79
+ :TRANSFER_FREE_BUFFER, 1 << 1,
80
+ :TRANSFER_FREE_TRANSFER, 1 << 2,
81
+ :TRANSFER_ADD_ZERO_PACKET, 1 << 3,
82
+ ]
83
+
84
+ # Values for {Endpoint#transfer_type}.
85
+ TransferTypes = enum :libusb_transfer_type, [
86
+ # Control endpoint
87
+ :TRANSFER_TYPE_CONTROL, 0,
88
+ # Isochronous endpoint
89
+ :TRANSFER_TYPE_ISOCHRONOUS, 1,
90
+ # Bulk endpoint
91
+ :TRANSFER_TYPE_BULK, 2,
92
+ # Interrupt endpoint
93
+ :TRANSFER_TYPE_INTERRUPT, 3,
94
+ # Stream endpoint
95
+ :TRANSFER_TYPE_BULK_STREAM, 4,
96
+ ]
97
+
98
+ StandardRequests = enum :libusb_standard_request, [
99
+ :REQUEST_GET_STATUS, 0x00,
100
+ :REQUEST_CLEAR_FEATURE, 0x01,
101
+ :REQUEST_SET_FEATURE, 0x03,
102
+ :REQUEST_SET_ADDRESS, 0x05,
103
+ :REQUEST_GET_DESCRIPTOR, 0x06,
104
+ :REQUEST_SET_DESCRIPTOR, 0x07,
105
+ :REQUEST_GET_CONFIGURATION, 0x08,
106
+ :REQUEST_SET_CONFIGURATION, 0x09,
107
+ :REQUEST_GET_INTERFACE, 0x0A,
108
+ :REQUEST_SET_INTERFACE, 0x0B,
109
+ :REQUEST_SYNCH_FRAME, 0x0C,
110
+ ]
111
+
112
+ EndpointDirections = enum :libusb_endpoint_direction, [
113
+ :ENDPOINT_IN, 0x80,
114
+ :ENDPOINT_OUT, 0x00,
115
+ ]
116
+
117
+ DescriptorTypes = enum :libusb_descriptor_type, [
118
+ # Device descriptor. See {Device}
119
+ :DT_DEVICE, 0x01,
120
+ # Configuration descriptor. See {Configuration}
121
+ :DT_CONFIG, 0x02,
122
+ # String descriptor
123
+ :DT_STRING, 0x03,
124
+ # Interface descriptor. See {Interface}
125
+ :DT_INTERFACE, 0x04,
126
+ # Endpoint descriptor. See {Endpoint}
127
+ :DT_ENDPOINT, 0x05,
128
+ # BOS descriptor
129
+ :DT_BOS, 0x0f,
130
+ # Device Capability descriptor
131
+ :DT_DEVICE_CAPABILITY, 0x10,
132
+ # HID descriptor
133
+ :DT_HID, 0x21,
134
+ # HID report descriptor
135
+ :DT_REPORT, 0x22,
136
+ # Physical descriptor
137
+ :DT_PHYSICAL, 0x23,
138
+ # Hub descriptor
139
+ :DT_HUB, 0x29,
140
+ # SuperSpeed Hub descriptor
141
+ :DT_SUPERSPEED_HUB, 0x2a,
142
+ # SuperSpeed Endpoint Companion descriptor
143
+ :DT_SS_ENDPOINT_COMPANION, 0x30,
144
+ ]
145
+
146
+ RequestTypes = enum :libusb_request_type, [
147
+ :REQUEST_TYPE_STANDARD, (0x00 << 5),
148
+ :REQUEST_TYPE_CLASS, (0x01 << 5),
149
+ :REQUEST_TYPE_VENDOR, (0x02 << 5),
150
+ :REQUEST_TYPE_RESERVED, (0x03 << 5),
151
+ ]
152
+
153
+ RequestRecipients = enum :libusb_request_recipient, [
154
+ :RECIPIENT_DEVICE, 0x00,
155
+ :RECIPIENT_INTERFACE, 0x01,
156
+ :RECIPIENT_ENDPOINT, 0x02,
157
+ :RECIPIENT_OTHER, 0x03,
158
+ ]
159
+
160
+ IsoSyncTypes = enum :libusb_iso_sync_type, [
161
+ :ISO_SYNC_TYPE_NONE, 0,
162
+ :ISO_SYNC_TYPE_ASYNC, 1,
163
+ :ISO_SYNC_TYPE_ADAPTIVE, 2,
164
+ :ISO_SYNC_TYPE_SYNC, 3,
165
+ ]
166
+
167
+ # Speed codes. Indicates the speed at which the device is operating.
168
+ Speeds = enum :libusb_speed, [
169
+ # The OS doesn't report or know the device speed.
170
+ :SPEED_UNKNOWN, 0,
171
+ # The device is operating at low speed (1.5MBit/s).
172
+ :SPEED_LOW, 1,
173
+ # The device is operating at full speed (12MBit/s).
174
+ :SPEED_FULL, 2,
175
+ # The device is operating at high speed (480MBit/s).
176
+ :SPEED_HIGH, 3,
177
+ # The device is operating at super speed (5000MBit/s).
178
+ :SPEED_SUPER, 4,
179
+ # The device is operating at super speed plus (10000MBit/s).
180
+ # Available since libusb-1.0.22
181
+ :SPEED_SUPER_PLUS, 5,
182
+ ]
183
+
184
+ # Supported speeds (wSpeedSupported) bitfield. Indicates what
185
+ # speeds the device supports.
186
+ SupportedSpeeds = enum :libusb_supported_speed, [
187
+ # Low speed operation supported (1.5MBit/s).
188
+ :LOW_SPEED_OPERATION, 1,
189
+ # Full speed operation supported (12MBit/s).
190
+ :FULL_SPEED_OPERATION, 2,
191
+ # High speed operation supported (480MBit/s).
192
+ :HIGH_SPEED_OPERATION, 4,
193
+ # Superspeed operation supported (5000MBit/s).
194
+ :SUPER_SPEED_OPERATION, 8,
195
+ ]
196
+
197
+ Capabilities = enum :libusb_capability, [
198
+ :CAP_HAS_CAPABILITY, 0x0000,
199
+ # Hotplug support is available on this platform.
200
+ :CAP_HAS_HOTPLUG, 0x0001,
201
+ # The library can access HID devices without requiring user intervention.
202
+ # Note that before being able to actually access an HID device, you may
203
+ # still have to call additional libusb functions such as
204
+ # {DevHandle#detach_kernel_driver}.
205
+ :CAP_HAS_HID_ACCESS, 0x0100,
206
+ # The library supports detaching of the default USB driver, using
207
+ # {DevHandle#detach_kernel_driver}, if one is set by the OS kernel.
208
+ :CAP_SUPPORTS_DETACH_KERNEL_DRIVER, 0x0101,
209
+ ]
210
+
211
+ # Masks for the bits of the
212
+ # {Bos::Usb20Extension#bmAttributes} field
213
+ # of the USB 2.0 Extension descriptor.
214
+ Usb20ExtensionAttributes = enum :libusb_usb_2_0_extension_attributes, [
215
+ # Supports Link Power Management (LPM)
216
+ :BM_LPM_SUPPORT, 2,
217
+ ]
218
+
219
+ # Masks for the bits of the
220
+ # {Bos::SsUsbDeviceCapability#bmAttributes} field
221
+ # field of the SuperSpeed USB Device Capability descriptor.
222
+ SsUsbDeviceCapabilityAttributes = enum :libusb_ss_usb_device_capability_attributes, [
223
+ # Supports Latency Tolerance Messages (LTM)
224
+ :BM_LTM_SUPPORT, 2,
225
+ ]
226
+
227
+ # USB capability types
228
+ #
229
+ # @see Bos::DeviceCapability
230
+ BosTypes = enum :libusb_bos_type, [
231
+ :BT_WIRELESS_USB_DEVICE_CAPABILITY, 0x01, # Wireless USB device capability
232
+ :BT_USB_2_0_EXTENSION, 0x02, # USB 2.0 extensions
233
+ :BT_SS_USB_DEVICE_CAPABILITY, 0x03, # SuperSpeed USB device capability
234
+ :BT_CONTAINER_ID, 0x04, # Container ID type
235
+ :BT_PLATFORM_DESCRIPTOR, 0x05, # Platform descriptor
236
+ :BT_POWER_DELIVERY_CAPABILITY, 0x06, # Defines the various PD Capabilities of this device
237
+ :BT_BATTERY_INFO_CAPABILITY, 0x07, # Provides information on each battery supported by the device
238
+ :BT_PD_CONSUMER_PORT_CAPABILITY, 0x08, # The consumer characteristics of a port on the device
239
+ :BT_PD_PROVIDER_PORT_CAPABILITY, 0x09, # The provider characteristics of a port on the device
240
+ :BT_SUPERSPEED_PLUS, 0x0A, # Defines the set of SuperSpeed Plus USB specific device level capabilities
241
+ :BT_PRECISION_TIME_MEASUREMENT, 0x0B, # Precision Time Measurement (PTM) Capability Descriptor
242
+ :BT_Wireless_USB_Ext, 0x0C, # Defines the set of Wireless USB 1.1-specific device level capabilities
243
+ :BT_BILLBOARD, 0x0D, # Billboard capability
244
+ :BT_AUTHENTICATION, 0x0E, # Authentication Capability Descriptor
245
+ :BT_BILLBOARD_EX, 0x0F, # Billboard Ex capability
246
+ :BT_CONFIGURATION_SUMMARY, 0x10, # Summarizes configuration information for a function implemented by the device
247
+ :BT_FWStatus_Capability, 0x11, # Describes the capability to support FWStatus
248
+ ]
249
+
250
+ # Since libusb version 1.0.16.
251
+ #
252
+ # Hotplug events
253
+ HotplugEvents = enum :libusb_hotplug_event, [
254
+ # A device has been plugged in and is ready to use.
255
+ :HOTPLUG_EVENT_DEVICE_ARRIVED, 0x01,
256
+
257
+ # A device has left and is no longer available.
258
+ # It is the user's responsibility to call libusb_close on any handle associated with a disconnected device.
259
+ # It is safe to call libusb_get_device_descriptor on a device that has left.
260
+ :HOTPLUG_EVENT_DEVICE_LEFT, 0x02,
261
+ ]
262
+
263
+ # Since libusb version 1.0.16.
264
+ #
265
+ # Flags for hotplug events */
266
+ HotplugFlags = enum :libusb_hotplug_flag, [
267
+ # Arm the callback and fire it for all matching currently attached devices.
268
+ :HOTPLUG_ENUMERATE, 1,
269
+ ]
270
+
271
+ # Log message levels.
272
+ #
273
+ # - :LOG_LEVEL_NONE (0) : no messages ever printed by the library (default)
274
+ # - :LOG_LEVEL_ERROR (1) : error messages are printed to stderr
275
+ # - :LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr
276
+ # - :LOG_LEVEL_INFO (3) : informational messages are printed to stderr
277
+ # - :LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to stderr
278
+ LogLevels = enum :libusb_log_level, [
279
+ :LOG_LEVEL_NONE, 0,
280
+ :LOG_LEVEL_ERROR, 1,
281
+ :LOG_LEVEL_WARNING, 2,
282
+ :LOG_LEVEL_INFO, 3,
283
+ :LOG_LEVEL_DEBUG, 4,
284
+ ]
285
+
286
+ # /** \ingroup libusb_lib
287
+ # * Log callback mode.
288
+ # *
289
+ # * Since version 1.0.23, \ref LIBUSB_API_VERSION >= 0x01000107
290
+ # *
291
+ # * \see libusb_set_log_cb()
292
+ # */
293
+ # enum libusb_log_cb_mode {
294
+ # /** Callback function handling all log messages. */
295
+ # LIBUSB_LOG_CB_GLOBAL = (1 << 0),
296
+ #
297
+ # /** Callback function handling context related log messages. */
298
+ # LIBUSB_LOG_CB_CONTEXT = (1 << 1)
299
+ # };
300
+ LogCbMode = enum :libusb_log_cb_mode, [
301
+ :LOG_CB_GLOBAL, (1 << 0),
302
+ :LOG_CB_CONTEXT, (1 << 1),
303
+ ]
304
+
305
+ # Available option values for {Context#set_option}.
306
+ Options = enum :libusb_option, [
307
+ # Set the log message verbosity.
308
+ #
309
+ # The default level is :LOG_LEVEL_NONE, which means no messages are ever
310
+ # printed. If you choose to increase the message verbosity level, ensure
311
+ # that your application does not close the stderr file descriptor.
312
+ #
313
+ # You are advised to use level :LOG_LEVEL_WARNING. libusb is conservative
314
+ # with its message logging and most of the time, will only log messages that
315
+ # explain error conditions and other oddities. This will help you debug
316
+ # your software.
317
+ #
318
+ # If the +LIBUSB_DEBUG+ environment variable was set when libusb was
319
+ # initialized, this function does nothing: the message verbosity is fixed
320
+ # to the value in the environment variable.
321
+ #
322
+ # If libusb was compiled without any message logging, this function does
323
+ # nothing: you'll never get any messages.
324
+ #
325
+ # If libusb was compiled with verbose debug message logging, this function
326
+ # does nothing: you'll always get messages from all levels.
327
+ :OPTION_LOG_LEVEL, 0,
328
+
329
+ # Use the UsbDk backend for a specific context, if available.
330
+ #
331
+ # This option should be set immediately after calling {Context.new}, otherwise
332
+ # unspecified behavior may occur.
333
+ #
334
+ # Only valid on Windows.
335
+ #
336
+ # Available since libusb-1.0.22.
337
+ :OPTION_USE_USBDK, 1,
338
+
339
+ # Do not scan for devices
340
+ #
341
+ # With this option set, libusb will skip scanning devices in
342
+ # libusb_init_context().
343
+ #
344
+ # Hotplug functionality will also be deactivated.
345
+ #
346
+ # The option is useful in combination with libusb_wrap_sys_device(),
347
+ # which can access a device directly without prior device scanning.
348
+ #
349
+ # This is typically needed on Android, where access to USB devices
350
+ # is limited.
351
+ #
352
+ # Only valid on Linux. Ignored on all other platforms.
353
+ :OPTION_NO_DEVICE_DISCOVERY, 2,
354
+
355
+ # Set the context log callback functon.
356
+ #
357
+ # Set the log callback function either on a context or globally.
358
+ # This option must be provided a Proc argument or +nil+ to remove the callback.
359
+ # Using this option with a +nil+ context is equivalent to calling libusb_set_log_cb with mode :LOG_CB_GLOBAL.
360
+ # Using it with a non- +nil+ context is equivalent to calling libusb_set_log_cb with mode :LOG_CB_CONTEXT.
361
+ :OPTION_LOG_CB, 3,
362
+
363
+ :OPTION_MAX, 4,
364
+ ]
365
+
366
+ typedef :pointer, :libusb_context
367
+ typedef :pointer, :libusb_device
368
+ typedef :pointer, :libusb_device_handle
369
+ typedef :pointer, :libusb_transfer
370
+ typedef :int, :libusb_hotplug_callback_handle
371
+
372
+ # /** \ingroup libusb_lib
373
+ # * Callback function for handling log messages.
374
+ # * \param ctx the context which is related to the log message, or +nil+ if it
375
+ # * is a global log message
376
+ # * \param level the log level, see \ref libusb_log_level for a description
377
+ # * \param str the log message
378
+ # *
379
+ # * Since version 1.0.23, \ref LIBUSB_API_VERSION >= 0x01000107
380
+ # *
381
+ # * \see libusb_set_log_cb()
382
+ # */
383
+ # typedef void (LIBUSB_CALL *libusb_log_cb)(libusb_context *ctx,
384
+ # enum libusb_log_level level, const char *str);
385
+ callback :libusb_log_cb, [:libusb_context, :libusb_log_level, :string], :void
386
+
387
+ # @private
388
+ # /** \ingroup libusb_lib
389
+ # * Structure used for setting options through \ref libusb_init_context.
390
+ # *
391
+ # */
392
+ # struct libusb_init_option {
393
+ # /** Which option to set */
394
+ # enum libusb_option option;
395
+ # /** An integer value used by the option (if applicable). */
396
+ # union {
397
+ # int64_t ival;
398
+ # libusb_log_cb log_cbval;
399
+ # } value;
400
+ # };
401
+ class InitOptionValue < FFI::Union
402
+ layout :ival, :int64_t,
403
+ :log_cbval, :libusb_log_cb
404
+ end
405
+ class InitOption < FFI::Struct
406
+ layout :option, :libusb_option,
407
+ :value, InitOptionValue
408
+ end
409
+
410
+ class << self
411
+ private def try_attach_function(method, *args, **kwargs)
412
+ if ffi_libraries.find{|lib| lib.find_function(method) }
413
+ attach_function method, *args, **kwargs
414
+ end
415
+ end
416
+ end
417
+
418
+ try_attach_function 'libusb_get_version', [], :pointer
419
+
420
+ attach_function 'libusb_init', [ :pointer ], :int
421
+ # int LIBUSB_CALL libusb_init_context(libusb_context **ctx, const struct libusb_init_option options[], int num_options);
422
+ try_attach_function 'libusb_init_context', [:pointer, :pointer, :int], :int
423
+ # may be deprecated in the future in favor of libusb_init_context()+libusb_set_option()
424
+ # void LIBUSB_CALL libusb_set_log_cb(libusb_context *ctx, libusb_log_cb cb, int mode);
425
+ try_attach_function 'libusb_set_log_cb', [:libusb_context, :libusb_log_cb, :int], :void
426
+ attach_function 'libusb_exit', [ :pointer ], :void
427
+ attach_function 'libusb_set_debug', [:pointer, :libusb_log_level], :void
428
+ try_attach_function 'libusb_set_option', [:libusb_context, :libusb_option, :varargs], :int
429
+ try_attach_function 'libusb_has_capability', [:libusb_capability], :int
430
+
431
+ attach_function 'libusb_get_device_list', [:pointer, :pointer], :ssize_t
432
+ attach_function 'libusb_free_device_list', [:pointer, :int], :void
433
+ attach_function 'libusb_ref_device', [:pointer], :pointer
434
+ attach_function 'libusb_unref_device', [:pointer], :void
435
+
436
+ attach_function 'libusb_get_device_descriptor', [:pointer, :pointer], :int
437
+ attach_function 'libusb_get_active_config_descriptor', [:pointer, :pointer], :int
438
+ attach_function 'libusb_get_config_descriptor', [:pointer, :uint8, :pointer], :int
439
+ attach_function 'libusb_get_config_descriptor_by_value', [:pointer, :uint8, :pointer], :int
440
+ attach_function 'libusb_free_config_descriptor', [:pointer], :void
441
+ attach_function 'libusb_get_bus_number', [:pointer], :uint8
442
+ try_attach_function 'libusb_get_port_number', [:pointer], :uint8
443
+ try_attach_function 'libusb_get_parent', [:pointer], :pointer
444
+ try_attach_function 'libusb_get_port_path', [:pointer, :pointer, :pointer, :uint8], :uint8
445
+ try_attach_function 'libusb_get_port_numbers', [:pointer, :pointer, :uint8], :uint8
446
+ attach_function 'libusb_get_device_address', [:pointer], :uint8
447
+ try_attach_function 'libusb_get_device_speed', [:pointer], :libusb_speed
448
+ attach_function 'libusb_get_max_packet_size', [:pointer, :uint8], :int
449
+ attach_function 'libusb_get_max_iso_packet_size', [:pointer, :uint8], :int
450
+ # int API_EXPORTED libusb_get_max_alt_packet_size(libusb_device *dev, int interface_number, int alternate_setting, unsigned char endpoint)
451
+ try_attach_function 'libusb_get_max_alt_packet_size', [:pointer, :int, :int, :uchar], :int
452
+
453
+ try_attach_function 'libusb_get_ss_endpoint_companion_descriptor', [:pointer, :pointer, :pointer], :int
454
+ try_attach_function 'libusb_free_ss_endpoint_companion_descriptor', [:pointer], :void
455
+
456
+ try_attach_function 'libusb_get_bos_descriptor', [:libusb_device_handle, :pointer], :int, blocking: true
457
+ try_attach_function 'libusb_free_bos_descriptor', [:pointer], :void
458
+ try_attach_function 'libusb_get_usb_2_0_extension_descriptor', [:libusb_context, :pointer, :pointer], :int
459
+ try_attach_function 'libusb_free_usb_2_0_extension_descriptor', [:pointer], :void
460
+ try_attach_function 'libusb_get_ss_usb_device_capability_descriptor', [:libusb_context, :pointer, :pointer], :int
461
+ try_attach_function 'libusb_free_ss_usb_device_capability_descriptor', [:pointer], :void
462
+ try_attach_function 'libusb_get_container_id_descriptor', [:libusb_context, :pointer, :pointer], :int
463
+ try_attach_function 'libusb_free_container_id_descriptor', [:pointer], :void
464
+ try_attach_function 'libusb_get_platform_descriptor', [:libusb_context, :pointer, :pointer], :int
465
+ try_attach_function 'libusb_free_platform_descriptor', [:pointer], :void
466
+
467
+ # int LIBUSB_CALL libusb_wrap_sys_device(libusb_context *ctx, intptr_t sys_dev, libusb_device_handle **dev_handle);
468
+ try_attach_function 'libusb_wrap_sys_device', [:libusb_context, :intptr_t, :pointer], :int
469
+ attach_function 'libusb_open', [:pointer, :pointer], :int
470
+ attach_function 'libusb_close', [:pointer], :void
471
+ attach_function 'libusb_get_device', [:libusb_device_handle], :pointer
472
+
473
+ attach_function 'libusb_set_configuration', [:libusb_device_handle, :int], :int, blocking: true
474
+ attach_function 'libusb_claim_interface', [:libusb_device_handle, :int], :int
475
+ attach_function 'libusb_release_interface', [:libusb_device_handle, :int], :int, blocking: true
476
+
477
+ attach_function 'libusb_open_device_with_vid_pid', [:pointer, :int, :int], :pointer
478
+
479
+ attach_function 'libusb_set_interface_alt_setting', [:libusb_device_handle, :int, :int], :int, blocking: true
480
+ attach_function 'libusb_clear_halt', [:libusb_device_handle, :int], :int, blocking: true
481
+ attach_function 'libusb_reset_device', [:libusb_device_handle], :int, blocking: true
482
+ try_attach_function 'libusb_alloc_streams', [:libusb_device_handle, :uint32, :pointer, :int], :int
483
+ try_attach_function 'libusb_free_streams', [:libusb_device_handle, :pointer, :int], :int
484
+ try_attach_function 'libusb_dev_mem_alloc', [:libusb_device_handle, :size_t], :pointer
485
+ try_attach_function 'libusb_dev_mem_free', [:libusb_device_handle, :pointer, :size_t], :int
486
+
487
+ attach_function 'libusb_kernel_driver_active', [:libusb_device_handle, :int], :int
488
+ attach_function 'libusb_detach_kernel_driver', [:libusb_device_handle, :int], :int
489
+ attach_function 'libusb_attach_kernel_driver', [:libusb_device_handle, :int], :int
490
+ try_attach_function 'libusb_set_auto_detach_kernel_driver', [:libusb_device_handle, :int], :int
491
+
492
+ attach_function 'libusb_get_string_descriptor_ascii', [:pointer, :uint8, :pointer, :int], :int
493
+
494
+ attach_function 'libusb_alloc_transfer', [:int], :pointer
495
+ attach_function 'libusb_submit_transfer', [:pointer], :int
496
+ attach_function 'libusb_cancel_transfer', [:pointer], :int
497
+ attach_function 'libusb_free_transfer', [:pointer], :void
498
+ try_attach_function 'libusb_transfer_set_stream_id', [:libusb_transfer, :uint32], :void
499
+ try_attach_function 'libusb_transfer_get_stream_id', [:libusb_transfer], :uint32
500
+
501
+ attach_function 'libusb_handle_events', [:libusb_context], :int, blocking: true
502
+ try_attach_function 'libusb_handle_events_completed', [:libusb_context, :pointer], :int, blocking: true
503
+ attach_function 'libusb_handle_events_timeout', [:libusb_context, :pointer], :int, blocking: true
504
+ try_attach_function 'libusb_handle_events_timeout_completed', [:libusb_context, :pointer, :pointer], :int, blocking: true
505
+ try_attach_function 'libusb_interrupt_event_handler', [:libusb_context], :void
506
+
507
+ callback :libusb_pollfd_added_cb, [:int, :short, :pointer], :void
508
+ callback :libusb_pollfd_removed_cb, [:int, :pointer], :void
509
+
510
+ attach_function 'libusb_get_pollfds', [:libusb_context], :pointer
511
+ attach_function 'libusb_get_next_timeout', [:libusb_context, :pointer], :int
512
+ attach_function 'libusb_set_pollfd_notifiers', [:libusb_context, :libusb_pollfd_added_cb, :libusb_pollfd_removed_cb, :pointer], :void
513
+ try_attach_function 'libusb_free_pollfds', [:pointer], :void
514
+
515
+ callback :libusb_transfer_cb_fn, [:pointer], :void
516
+
517
+ callback :libusb_hotplug_callback_fn, [:libusb_context, :libusb_device, :libusb_hotplug_event, :pointer], :int
518
+ try_attach_function 'libusb_hotplug_register_callback', [
519
+ :libusb_context, :libusb_hotplug_event, :libusb_hotplug_flag,
520
+ :int, :int, :int, :libusb_hotplug_callback_fn,
521
+ :pointer, :pointer], :int
522
+ try_attach_function 'libusb_hotplug_deregister_callback', [:libusb_context, :libusb_hotplug_callback_handle], :void
523
+
524
+ class IsoPacketDescriptor < FFI::Struct
525
+ layout :length, :uint,
526
+ :actual_length, :uint,
527
+ :status, :libusb_transfer_status
528
+ end
529
+
530
+ # Setup packet for control transfers.
531
+ class ControlSetup < FFI::Struct
532
+ layout :bmRequestType, :uint8,
533
+ :bRequest, :uint8,
534
+ :wValue, :uint16,
535
+ :wIndex, :uint16,
536
+ :wLength, :uint16
537
+ end
538
+
539
+ class Transfer < FFI::Struct
540
+ layout :dev_handle, :libusb_device_handle,
541
+ :flags, :uint8,
542
+ :endpoint, :uchar,
543
+ :type, :uchar,
544
+ :timeout, :uint,
545
+ :status, :libusb_transfer_status,
546
+ :length, :int,
547
+ :actual_length, :int,
548
+ :callback, :libusb_transfer_cb_fn,
549
+ :user_data, :pointer,
550
+ :buffer, :pointer,
551
+ :num_iso_packets, :int
552
+
553
+ def initialize(*)
554
+ super
555
+
556
+ ptr = pointer
557
+ def ptr.free_struct(id)
558
+ Call.libusb_free_transfer(self)
559
+ return unless @ctx
560
+ @ctx.unref_context
561
+ end
562
+ # The ctx pointer is not yet assigned.
563
+ # It happens at LIBUSB::Transfer#dev_handle= later on.
564
+ ptr.instance_variable_set(:@ctx, nil)
565
+ ObjectSpace.define_finalizer(self, ptr.method(:free_struct))
566
+ end
567
+ end
568
+
569
+ class DeviceDescriptor < FFI::Struct
570
+ include Comparable
571
+
572
+ layout :bLength, :uint8,
573
+ :bDescriptorType, :uint8,
574
+ :bcdUSB, :uint16,
575
+ :bDeviceClass, :uint8,
576
+ :bDeviceSubClass, :uint8,
577
+ :bDeviceProtocol, :uint8,
578
+ :bMaxPacketSize0, :uint8,
579
+ :idVendor, :uint16,
580
+ :idProduct, :uint16,
581
+ :bcdDevice, :uint16,
582
+ :iManufacturer, :uint8,
583
+ :iProduct, :uint8,
584
+ :iSerialNumber, :uint8,
585
+ :bNumConfigurations, :uint8
586
+ end
587
+
588
+ class Timeval < FFI::Struct
589
+ layout :tv_sec, :long,
590
+ :tv_usec, :long
591
+
592
+ # set timeval to the number of milliseconds
593
+ # @param [Fixnum] value
594
+ def in_ms=(value)
595
+ self[:tv_sec], self[:tv_usec] = (value*1000).divmod(1000000)
596
+ end
597
+
598
+ # get the number of milliseconds in timeval
599
+ # @return [Fixnum]
600
+ def in_ms
601
+ self[:tv_sec]*1000 + self[:tv_usec]/1000
602
+ end
603
+
604
+ # set timeval to the number of seconds
605
+ # @param [Numeric] value
606
+ def in_s=(value)
607
+ self[:tv_sec], self[:tv_usec] = (value*1000000).divmod(1000000)
608
+ end
609
+
610
+ # get the number of seconds in timeval
611
+ # @return [Float]
612
+ def in_s
613
+ self[:tv_sec] + self[:tv_usec]/1000000.0
614
+ end
615
+ end
616
+
617
+ class Pollfd < FFI::Struct
618
+ layout :fd, :int,
619
+ :events, :short
620
+ end
621
+ end
622
+ end