Verify that interface and alternate numbers are 0-based indices, we rely
on this assumption in the config.
This commit is contained in:
@@ -228,7 +228,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
|
|||||||
Cap: int(cfg.bNumInterfaces),
|
Cap: int(cfg.bNumInterfaces),
|
||||||
}
|
}
|
||||||
c.Interfaces = make([]InterfaceInfo, 0, len(ifaces))
|
c.Interfaces = make([]InterfaceInfo, 0, len(ifaces))
|
||||||
for _, iface := range ifaces {
|
for ifNum, iface := range ifaces {
|
||||||
if iface.num_altsetting == 0 {
|
if iface.num_altsetting == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -240,7 +240,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
|
|||||||
Cap: int(iface.num_altsetting),
|
Cap: int(iface.num_altsetting),
|
||||||
}
|
}
|
||||||
descs := make([]InterfaceSetting, 0, len(alts))
|
descs := make([]InterfaceSetting, 0, len(alts))
|
||||||
for _, alt := range alts {
|
for altNum, alt := range alts {
|
||||||
i := InterfaceSetting{
|
i := InterfaceSetting{
|
||||||
Number: int(alt.bInterfaceNumber),
|
Number: int(alt.bInterfaceNumber),
|
||||||
Alternate: int(alt.bAlternateSetting),
|
Alternate: int(alt.bAlternateSetting),
|
||||||
@@ -248,6 +248,12 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
|
|||||||
SubClass: Class(alt.bInterfaceSubClass),
|
SubClass: Class(alt.bInterfaceSubClass),
|
||||||
Protocol: Protocol(alt.bInterfaceProtocol),
|
Protocol: Protocol(alt.bInterfaceProtocol),
|
||||||
}
|
}
|
||||||
|
if ifNum != i.Number {
|
||||||
|
return nil, fmt.Errorf("config %d interface at index %d has number %d, USB standard states they should be identical", c.Config, ifNum, i.Number)
|
||||||
|
}
|
||||||
|
if altNum != i.Alternate {
|
||||||
|
return nil, fmt.Errorf("config %d interface %d alternate settings at index %d has number %d, USB standard states they should be identical", c.Config, i.Number, altNum, i.Alternate)
|
||||||
|
}
|
||||||
var ends []C.struct_libusb_endpoint_descriptor
|
var ends []C.struct_libusb_endpoint_descriptor
|
||||||
*(*reflect.SliceHeader)(unsafe.Pointer(&ends)) = reflect.SliceHeader{
|
*(*reflect.SliceHeader)(unsafe.Pointer(&ends)) = reflect.SliceHeader{
|
||||||
Data: uintptr(unsafe.Pointer(alt.endpoint)),
|
Data: uintptr(unsafe.Pointer(alt.endpoint)),
|
||||||
|
Reference in New Issue
Block a user