Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Jul 2011 10:48:39 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r224213 - stable/8/lib/libusb
Message-ID:  <201107191048.p6JAmdPC067250@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Tue Jul 19 10:48:39 2011
New Revision: 224213
URL: http://svn.freebsd.org/changeset/base/224213

Log:
  MFC r224085:
  - Add missing APIs.
  - Add some rangechecks.

Modified:
  stable/8/lib/libusb/libusb.3
  stable/8/lib/libusb/libusb01.c
  stable/8/lib/libusb/libusb10.c
  stable/8/lib/libusb/libusb10_desc.c
  stable/8/lib/libusb/libusb20.c
  stable/8/lib/libusb/usb.h   (contents, props changed)
Directory Properties:
  stable/8/lib/libusb/   (props changed)

Modified: stable/8/lib/libusb/libusb.3
==============================================================================
--- stable/8/lib/libusb/libusb.3	Tue Jul 19 10:45:31 2011	(r224212)
+++ stable/8/lib/libusb/libusb.3	Tue Jul 19 10:48:39 2011	(r224213)
@@ -542,6 +542,8 @@ The library is also compliant with LibUS
 .Fn usb_device
 .Fn usb_get_busses
 .Fn usb_check_connected
+.Fn usb_get_driver_np
+.Fn usb_detach_kernel_driver_np
 .
 .Sh SEE ALSO
 .Xr libusb20 3 ,

Modified: stable/8/lib/libusb/libusb01.c
==============================================================================
--- stable/8/lib/libusb/libusb01.c	Tue Jul 19 10:45:31 2011	(r224212)
+++ stable/8/lib/libusb/libusb01.c	Tue Jul 19 10:48:39 2011	(r224213)
@@ -203,6 +203,12 @@ usb_get_string(usb_dev_handle * dev, int
 {
 	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 * d
 {
 	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_h
 {
 	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
 {
 	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);
+}

Modified: stable/8/lib/libusb/libusb10.c
==============================================================================
--- stable/8/lib/libusb/libusb10.c	Tue Jul 19 10:45:31 2011	(r224212)
+++ stable/8/lib/libusb/libusb10.c	Tue Jul 19 10:48:39 2011	(r224213)
@@ -719,6 +719,8 @@ libusb_get_driver(struct libusb20_device
 		return (LIBUSB_ERROR_INVALID_PARAM);
 	if (namelen < 1)
 		return (LIBUSB_ERROR_INVALID_PARAM);
+	if (namelen > 255)
+		namelen = 255;
 
 	err = libusb20_dev_get_iface_desc(
 	    pdev, interface, name, namelen);

Modified: stable/8/lib/libusb/libusb10_desc.c
==============================================================================
--- stable/8/lib/libusb/libusb10_desc.c	Tue Jul 19 10:45:31 2011	(r224212)
+++ stable/8/lib/libusb/libusb10_desc.c	Tue Jul 19 10:48:39 2011	(r224213)
@@ -300,6 +300,9 @@ libusb_get_string_descriptor_ascii(libus
 	if (pdev == NULL || data == NULL || length < 1)
 		return (LIBUSB20_ERROR_INVALID_PARAM);
 
+	if (length > 65535)
+		length = 65535;
+
 	/* put some default data into the destination buffer */
 	data[0] = 0;
 
@@ -314,6 +317,12 @@ int
 libusb_get_descriptor(libusb_device_handle * devh, uint8_t desc_type, 
     uint8_t desc_index, uint8_t *data, int length)
 {
+	if (devh == NULL || data == NULL || length < 1)
+		return (LIBUSB20_ERROR_INVALID_PARAM);
+
+	if (length > 65535)
+		length = 65535;
+
 	return (libusb_control_transfer(devh, LIBUSB_ENDPOINT_IN,
 	    LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data,
 	    length, 1000));

Modified: stable/8/lib/libusb/libusb20.c
==============================================================================
--- stable/8/lib/libusb/libusb20.c	Tue Jul 19 10:45:31 2011	(r224212)
+++ stable/8/lib/libusb/libusb20.c	Tue Jul 19 10:48:39 2011	(r224213)
@@ -1081,6 +1081,8 @@ libusb20_dev_get_iface_desc(struct libus
 	if ((buf == NULL) || (len == 0))
 		return (LIBUSB20_ERROR_INVALID_PARAM);
 
+	buf[0] = 0;		/* set default string value */
+
 	return (pdev->beMethods->dev_get_iface_desc(
 	    pdev, iface_index, buf, len));
 }

Modified: stable/8/lib/libusb/usb.h
==============================================================================
--- stable/8/lib/libusb/usb.h	Tue Jul 19 10:45:31 2011	(r224212)
+++ stable/8/lib/libusb/usb.h	Tue Jul 19 10:48:39 2011	(r224213)
@@ -299,6 +299,8 @@ int	usb_find_busses(void);
 int	usb_find_devices(void);
 struct usb_device *usb_device(usb_dev_handle * dev);
 struct usb_bus *usb_get_busses(void);
+int	usb_get_driver_np(usb_dev_handle * dev, int interface, char *name, int namelen);
+int	usb_detach_kernel_driver_np(usb_dev_handle * dev, int interface);
 
 #if 0
 {					/* style */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107191048.p6JAmdPC067250>