diff --git a/include/sane/sanei_usb.h b/include/sane/sanei_usb.h index 0f3c1569e..a321ce495 100644 --- a/include/sane/sanei_usb.h +++ b/include/sane/sanei_usb.h @@ -162,6 +162,18 @@ #define USB_DIR_IN 0x80 /* @} */ +/** */ +struct sanei_usb_dev_descriptor +{ + SANE_Byte desc_type; + unsigned int bcd_usb; + unsigned int bcd_dev; + SANE_Byte dev_class; + SANE_Byte dev_sub_class; + SANE_Byte dev_protocol; + SANE_Byte max_packet_size; +}; + /** Initialize sanei_usb. * * Call this before any other sanei_usb function. @@ -416,5 +428,24 @@ sanei_usb_release_interface (SANE_Int dn, SANE_Int interface_number); extern SANE_Status sanei_usb_set_altinterface (SANE_Int dn, SANE_Int alternate); +/** Get some information from the device descriptor + * + * Sometimes it's useful to know something about revisions and + * other stuff reported by the USB system + * + * @param dn device number + * @param desc, where to put the information to + * + * @return + * - SANE_STATUS_GOOD - on succes + * - SANE_STATUS_UNSUPPORTED - if the feature is not supported by the OS or + * SANE. + * - SANE_STATUS_INVAL - on every other error + * + */ + +extern SANE_Status +sanei_usb_get_descriptor( SANE_Int dn, struct sanei_usb_dev_descriptor *desc ); + /*------------------------------------------------------*/ #endif /* sanei_usb_h */ diff --git a/sanei/sanei_usb.c b/sanei/sanei_usb.c index e58c940a5..0106a3a57 100644 --- a/sanei/sanei_usb.c +++ b/sanei/sanei_usb.c @@ -1922,3 +1922,38 @@ sanei_usb_set_altinterface (SANE_Int dn, SANE_Int alternate) return SANE_STATUS_UNSUPPORTED; } } + +extern SANE_Status +sanei_usb_get_descriptor( SANE_Int dn, struct sanei_usb_dev_descriptor *desc ) +{ + if (dn >= MAX_DEVICES || dn < 0) + { + DBG (1, + "sanei_usb_get_descriptor: dn >= MAX_DEVICES || dn < 0, dn=%d\n", + dn); + return SANE_STATUS_INVAL; + } + + DBG (5, "sanei_usb_get_descriptor\n"); +#ifdef HAVE_LIBUSB + { + struct usb_device_descriptor *usb_descr; + + usb_descr = &(devices[dn].libusb_device->descriptor); + desc->desc_type = usb_descr->bDescriptorType; + desc->bcd_usb = usb_descr->bcdUSB; + desc->bcd_dev = usb_descr->bcdDevice; + desc->dev_class = usb_descr->bDeviceClass; + + desc->dev_sub_class = usb_descr->bDeviceSubClass; + desc->dev_protocol = usb_descr->bDeviceProtocol; + desc->max_packet_size = usb_descr->bMaxPacketSize0; + return SANE_STATUS_GOOD; + } +#else /* not HAVE_LIBUSB */ + { + DBG (1, "sanei_usb_get_descriptor: libusb support missing\n"); + return SANE_STATUS_UNSUPPORTED; + } +#endif /* not HAVE_LIBUSB */ +}