Class: LIBUSB::Bos

Inherits:
FFI::ManagedStruct
  • Object
show all
Defined in:
lib/libusb/bos.rb

Overview

A structure representing the Binary Device Object Store (BOS) descriptor. This descriptor is documented in section 9.6.2 of the USB 3.0 specification. All multiple-byte fields are represented in host-endian format.

Defined Under Namespace

Modules: GenericMethods Classes: ContainerId, DeviceCapability, SsUsbDeviceCapability, Usb20Extension

Instance Method Summary collapse

Constructor Details

#initialize(ctx, *args) ⇒ Bos

Returns a new instance of Bos.



220
221
222
223
# File 'lib/libusb/bos.rb', line 220

def initialize( ctx, *args)
  @ctx = ctx
  super(*args)
end

Instance Method Details

#bDescriptorTypeInteger

in this context.

Returns:

  • (Integer)

    Descriptor type. Will have value LIBUSB::DT_BOS LIBUSB_DT_BOS



238
239
240
# File 'lib/libusb/bos.rb', line 238

def bDescriptorType
  self[:bDescriptorType]
end

#bLengthInteger

Returns Size of this descriptor (in bytes).

Returns:

  • (Integer)

    Size of this descriptor (in bytes)



232
233
234
# File 'lib/libusb/bos.rb', line 232

def bLength
  self[:bLength]
end

#bNumDeviceCapsInteger

the BOS

Returns:

  • (Integer)

    The number of separate device capability descriptors in



249
250
251
# File 'lib/libusb/bos.rb', line 249

def bNumDeviceCaps
  self[:bNumDeviceCaps]
end

#device_capabilitiesArray<Bos::DeviceCapability, Bos::Usb20Extension, Bos::SsUsbDeviceCapability, Bos::ContainerId>

bNumDeviceCap Device Capability Descriptors



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/libusb/bos.rb', line 256

def device_capabilities
  pp_ext = FFI::MemoryPointer.new :pointer
  caps = []
  # Capabilities are appended to the bos header
  ptr = pointer + offset_of(:dev_capability)
  bNumDeviceCaps.times do
    cap = DeviceCapability.new self, ptr.read_pointer
    case cap.bDevCapabilityType
      when LIBUSB::BT_WIRELESS_USB_DEVICE_CAPABILITY
        # no struct defined in libusb -> use generic DeviceCapability
      when LIBUSB::BT_USB_2_0_EXTENSION
        res = Call.libusb_get_usb_2_0_extension_descriptor(@ctx, cap.pointer, pp_ext)
        cap = Usb20Extension.new(pp_ext.read_pointer) if res==0
      when LIBUSB::BT_SS_USB_DEVICE_CAPABILITY
        res = Call.libusb_get_ss_usb_device_capability_descriptor(@ctx, cap.pointer, pp_ext)
        cap = SsUsbDeviceCapability.new(pp_ext.read_pointer) if res==0
      when LIBUSB::BT_CONTAINER_ID
        res = Call.libusb_get_container_id_descriptor(@ctx, cap.pointer, pp_ext)
        cap = ContainerId.new(pp_ext.read_pointer) if res==0
      else
        # unknown capability -> use generic DeviceCapability
    end
    ptr += FFI.type_size(:pointer)
    caps << cap
  end
  caps
end

#device_capability_typesArray<Symbol>

Returns Types of Capabilities.

Returns:

  • (Array<Symbol>)

    Types of Capabilities

See Also:



287
288
289
290
291
292
293
294
295
# File 'lib/libusb/bos.rb', line 287

def device_capability_types
  # Capabilities are appended to the bos header
  ptr = pointer + offset_of(:dev_capability)
  bNumDeviceCaps.times.map do
    cap = DeviceCapability.new self, ptr.read_pointer
    ptr += FFI.type_size(:pointer)
    Call::BosTypes.find cap.bDevCapabilityType
  end
end

#inspectObject



297
298
299
# File 'lib/libusb/bos.rb', line 297

def inspect
  "\#<#{self.class} #{device_capability_types.join(", ")}>"
end

#wTotalLengthInteger

Returns Length of this descriptor and all of its sub descriptors.

Returns:

  • (Integer)

    Length of this descriptor and all of its sub descriptors



243
244
245
# File 'lib/libusb/bos.rb', line 243

def wTotalLength
  self[:wTotalLength]
end