diff --git a/constants.go b/constants.go index aa1ce40..a301aad 100644 --- a/constants.go +++ b/constants.go @@ -94,15 +94,16 @@ type DescriptorType uint8 // Descriptor types defined by the USB spec. const ( - DescriptorTypeDevice DescriptorType = C.LIBUSB_DT_DEVICE - DescriptorTypeConfig DescriptorType = C.LIBUSB_DT_CONFIG - DescriptorTypeString DescriptorType = C.LIBUSB_DT_STRING - DescriptorTypeInterface DescriptorType = C.LIBUSB_DT_INTERFACE - DescriptorTypeEndpoint DescriptorType = C.LIBUSB_DT_ENDPOINT - DescriptorTypeHID DescriptorType = C.LIBUSB_DT_HID - DescriptorTypeReport DescriptorType = C.LIBUSB_DT_REPORT - DescriptorTypePhysical DescriptorType = C.LIBUSB_DT_PHYSICAL - DescriptorTypeHub DescriptorType = C.LIBUSB_DT_HUB + DescriptorTypeDevice DescriptorType = C.LIBUSB_DT_DEVICE + DescriptorTypeConfig DescriptorType = C.LIBUSB_DT_CONFIG + DescriptorTypeString DescriptorType = C.LIBUSB_DT_STRING + DescriptorTypeInterface DescriptorType = C.LIBUSB_DT_INTERFACE + DescriptorTypeCSInterface DescriptorType = 0x24 + DescriptorTypeEndpoint DescriptorType = C.LIBUSB_DT_ENDPOINT + DescriptorTypeHID DescriptorType = C.LIBUSB_DT_HID + DescriptorTypeReport DescriptorType = C.LIBUSB_DT_REPORT + DescriptorTypePhysical DescriptorType = C.LIBUSB_DT_PHYSICAL + DescriptorTypeHub DescriptorType = C.LIBUSB_DT_HUB ) var descriptorTypeDescription = map[DescriptorType]string{ diff --git a/interface.go b/interface.go index 0af77a9..0ae125f 100644 --- a/interface.go +++ b/interface.go @@ -35,6 +35,11 @@ func (i InterfaceDesc) String() string { return fmt.Sprintf("Interface %d (%d alternate settings)", i.Number, len(i.AltSettings)) } +type RawDescriptor struct { + Type DescriptorType + Data []byte +} + // InterfaceSetting contains information about a USB interface with a particular // alternate setting, extracted from the descriptor. type InterfaceSetting struct { @@ -51,6 +56,9 @@ type InterfaceSetting struct { // Endpoints enumerates the endpoints available on this interface with // this alternate setting. Endpoints map[EndpointAddress]EndpointDesc + // Extra interface descriptors, these are descriptors that are not part of the USB spec + // Potential examples are Class-Specific VC Interface Descriptor (UVC spec) + ExtraDescriptors []*RawDescriptor iInterface int // index of a string descriptor describing this interface. } diff --git a/libusb.go b/libusb.go index ddc0b2a..b380ea5 100644 --- a/libusb.go +++ b/libusb.go @@ -301,13 +301,28 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*DeviceDesc, error) { } descs := make([]InterfaceSetting, 0, len(alts)) for _, alt := range alts { + + var extraDescriptors []*RawDescriptor + extra := C.GoBytes(unsafe.Pointer(alt.extra), alt.extra_length) + for i := 0; i != len(extra); i += int(extra[i]) { + block := extra[i : i+int(extra[i])] + bType := DescriptorType(block[1]) + + extraDescriptors = append(extraDescriptors, + &RawDescriptor{ + Type: bType, + Data: block}, + ) + } + i := InterfaceSetting{ - Number: int(alt.bInterfaceNumber), - Alternate: int(alt.bAlternateSetting), - Class: Class(alt.bInterfaceClass), - SubClass: Class(alt.bInterfaceSubClass), - Protocol: Protocol(alt.bInterfaceProtocol), - iInterface: int(alt.iInterface), + Number: int(alt.bInterfaceNumber), + Alternate: int(alt.bAlternateSetting), + Class: Class(alt.bInterfaceClass), + SubClass: Class(alt.bInterfaceSubClass), + Protocol: Protocol(alt.bInterfaceProtocol), + ExtraDescriptors: extraDescriptors, + iInterface: int(alt.iInterface), } if hasIntf[i.Number][i.Alternate] {