diff options
author | hselasky <hselasky@FreeBSD.org> | 2011-07-16 08:29:12 +0000 |
---|---|---|
committer | hselasky <hselasky@FreeBSD.org> | 2011-07-16 08:29:12 +0000 |
commit | cbcc560b1ef4e3268956232dcc43c9f45bbb9e42 (patch) | |
tree | d29e1041d5757acef0079a9d43dae3ebbc16d7ec /lib/libusb/libusb01.c | |
parent | b3e331350eb3f9280f1c520a93d51993df0a659a (diff) | |
download | FreeBSD-src-cbcc560b1ef4e3268956232dcc43c9f45bbb9e42.zip FreeBSD-src-cbcc560b1ef4e3268956232dcc43c9f45bbb9e42.tar.gz |
- Add two missing functions to the LibUSB v0.1 API.
- Clamp the string length to 255 bytes when getting
the interface description.
- Clamp data request length to 65535 bytes when doing
control requests.
MFC after: 3 days
Diffstat (limited to 'lib/libusb/libusb01.c')
-rw-r--r-- | lib/libusb/libusb01.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/libusb/libusb01.c b/lib/libusb/libusb01.c index 4124ef6..17edb0e 100644 --- a/lib/libusb/libusb01.c +++ b/lib/libusb/libusb01.c @@ -203,6 +203,12 @@ usb_get_string(usb_dev_handle * dev, int strindex, { int err; + if (dev == NULL) + return (-1); + + if (buflen > 65535) + buflen = 65535; + err = libusb20_dev_req_string_sync((void *)dev, strindex, langid, buf, buflen); @@ -218,6 +224,12 @@ usb_get_string_simple(usb_dev_handle * dev, int strindex, { int err; + if (dev == NULL) + return (-1); + + if (buflen > 65535) + buflen = 65535; + err = libusb20_dev_req_string_simple_sync((void *)dev, strindex, buf, buflen); @@ -233,6 +245,12 @@ usb_get_descriptor_by_endpoint(usb_dev_handle * udev, int ep, uint8_t type, { memset(buf, 0, size); + if (udev == NULL) + return (-1); + + if (size > 65535) + size = 65535; + return (usb_control_msg(udev, ep | USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (type << 8) + ep_index, 0, buf, size, 1000)); @@ -244,6 +262,12 @@ usb_get_descriptor(usb_dev_handle * udev, uint8_t type, uint8_t desc_index, { memset(buf, 0, size); + if (udev == NULL) + return (-1); + + if (size > 65535) + size = 65535; + return (usb_control_msg(udev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (type << 8) + desc_index, 0, buf, size, 1000)); } @@ -943,3 +967,49 @@ usb_get_busses(void) { return (usb_busses); } + +int +usb_get_driver_np(usb_dev_handle * dev, int interface, char *name, int namelen) +{ + struct libusb20_device *pdev; + char *ptr; + int err; + + pdev = (void *)dev; + + if (pdev == NULL) + return (-1); + if (namelen < 1) + return (-1); + if (namelen > 255) + namelen = 255; + + err = libusb20_dev_get_iface_desc(pdev, interface, name, namelen); + if (err != 0) + return (-1); + + /* we only want the driver name */ + ptr = strstr(name, ":"); + if (ptr != NULL) + *ptr = 0; + + return (0); +} + +int +usb_detach_kernel_driver_np(usb_dev_handle * dev, int interface) +{ + struct libusb20_device *pdev; + int err; + + pdev = (void *)dev; + + if (pdev == NULL) + return (-1); + + err = libusb20_dev_detach_kernel_driver(pdev, interface); + if (err != 0) + return (-1); + + return (0); +} |