-
Notifications
You must be signed in to change notification settings - Fork 133
Add unknown interface descriptors to Extra #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. document the type. In particular whether the header of the descriptor (type+length) is a part of the data is an important information here. |
||
| 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. | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. join the line for append (i.e. the &RawDescriptor literal starts in the same line) |
||
| &RawDescriptor{ | ||
| Type: bType, | ||
| Data: block}, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. closing curly brace on the next line, together with closing parenthesis |
||
| ) | ||
| } | ||
|
|
||
|
Comment on lines
+305
to
+317
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extract to a helper function, since we're going to use that on interfaces as well as endpoints and configs. |
||
| 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] { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about CSEndpoint?
also add a comment to specify where the value was sourced from. (in this case I assume this is CDC spec v1.1/1.2?), since this descriptor type is not a part of the USB spec as such.