diff --git a/libusbhost/include/usbhost/usbhost.h b/libusbhost/include/usbhost/usbhost.h index a8dd6737c..86cc8732a 100644 --- a/libusbhost/include/usbhost/usbhost.h +++ b/libusbhost/include/usbhost/usbhost.h @@ -137,8 +137,15 @@ uint16_t usb_device_get_vendor_id(struct usb_device *device); /* Returns the USB product ID from the device descriptor for the USB device */ uint16_t usb_device_get_product_id(struct usb_device *device); +/* Returns a pointer to device descriptor */ const struct usb_device_descriptor* usb_device_get_device_descriptor(struct usb_device *device); +/* Returns the length in bytes read into the raw descriptors array */ +size_t usb_device_get_descriptors_length(const struct usb_device* device); + +/* Returns a pointer to the raw descriptors array */ +const unsigned char* usb_device_get_raw_descriptors(const struct usb_device* device); + /* Returns a USB descriptor string for the given string ID. * Used to implement usb_device_get_manufacturer_name, * usb_device_get_product_name and usb_device_get_serial. diff --git a/libusbhost/usbhost.c b/libusbhost/usbhost.c index 44b878d2c..77c264bc7 100644 --- a/libusbhost/usbhost.c +++ b/libusbhost/usbhost.c @@ -80,9 +80,11 @@ struct usb_host_context { int wddbus; }; +#define MAX_DESCRIPTORS_LENGTH 4096 + struct usb_device { char dev_name[64]; - unsigned char desc[4096]; + unsigned char desc[MAX_DESCRIPTORS_LENGTH]; int desc_length; int fd; int writeable; @@ -381,6 +383,8 @@ struct usb_device *usb_device_new(const char *dev_name, int fd) return device; failed: + // TODO It would be more appropriate to have callers do this + // since this function doesn't "own" this file descriptor. close(fd); free(device); return NULL; @@ -449,11 +453,18 @@ uint16_t usb_device_get_product_id(struct usb_device *device) return __le16_to_cpu(desc->idProduct); } -const struct usb_device_descriptor* usb_device_get_device_descriptor(struct usb_device *device) -{ +const struct usb_device_descriptor* usb_device_get_device_descriptor(struct usb_device* device) { return (struct usb_device_descriptor*)device->desc; } +size_t usb_device_get_descriptors_length(const struct usb_device* device) { + return device->desc_length; +} + +const unsigned char* usb_device_get_raw_descriptors(const struct usb_device* device) { + return device->desc; +} + char* usb_device_get_string(struct usb_device *device, int id, int timeout) { char string[256];