From 09a9b6ae5f523d1081ab7f4b49b81c9f1c73be24 Mon Sep 17 00:00:00 2001 From: Brendan Erwin Date: Fri, 22 Dec 2023 14:40:18 +0000 Subject: [PATCH] Allow bulk transfer type in addition to interrupt More careful checking of the endpoint attributes to look only at the bits indicating transfer type. A little more paranoia while checking the endpoint address direction as well. Not assuming non-IN is OUT now. --- raw_enabled.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/raw_enabled.go b/raw_enabled.go index 54c02eb..9f43034 100644 --- a/raw_enabled.go +++ b/raw_enabled.go @@ -120,7 +120,6 @@ func enumerateRawWithRef(vendorID uint16, productID uint16) ([]DeviceInfo, error if alt.bInterfaceClass == C.LIBUSB_CLASS_HID { continue } - // Find the endpoints that can speak libusb interrupts var ends []C.struct_libusb_endpoint_descriptor *(*reflect.SliceHeader)(unsafe.Pointer(&ends)) = reflect.SliceHeader{ Data: uintptr(unsafe.Pointer(alt.endpoint)), @@ -129,14 +128,18 @@ func enumerateRawWithRef(vendorID uint16, productID uint16) ([]DeviceInfo, error } var reader, writer *uint8 for _, end := range ends { - // Skip any non-interrupt endpoints - if end.bmAttributes != C.LIBUSB_TRANSFER_TYPE_INTERRUPT { - continue + maskedAttributes := end.bmAttributes & C.LIBUSB_TRANSFER_TYPE_MASK + is_interrupt := maskedAttributes == C.LIBUSB_TRANSFER_TYPE_INTERRUPT + is_bulk := maskedAttributes == C.LIBUSB_TRANSFER_TYPE_BULK + + if !is_interrupt && !is_bulk { + continue // Skip non-interrupt and non-bulk endpoints } + if end.bEndpointAddress&C.LIBUSB_ENDPOINT_IN == C.LIBUSB_ENDPOINT_IN { reader = new(uint8) *reader = uint8(end.bEndpointAddress) - } else { + } else if end.bEndpointAddress&C.LIBUSB_ENDPOINT_OUT == C.LIBUSB_ENDPOINT_OUT { writer = new(uint8) *writer = uint8(end.bEndpointAddress) }