PERFORCE change 174789 for review

Hans Petter Selasky hselasky at FreeBSD.org
Wed Feb 17 16:25:51 UTC 2010


http://p4web.freebsd.org/chv.cgi?CH=174789

Change 174789 by hselasky at hselasky_laptop001 on 2010/02/17 16:25:41

	New feature in USB template framework for USB device side mode:
		- make the usb_temp_setup() and usb_temp_unsetup() functions public
		so that other modules can generate USB descriptors.
		- extend the vendor specific request function by one
		  length pointer argument, because not all descriptors
		  store the length in the first byte. For example
		  HID descriptors.
		- patch by: HPS @

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb/template/usb_template.c#12 edit
.. //depot/projects/usb/src/sys/dev/usb/template/usb_template.h#4 edit
.. //depot/projects/usb/src/sys/dev/usb/template/usb_template_mtp.c#5 edit

Differences ...

==== //depot/projects/usb/src/sys/dev/usb/template/usb_template.c#12 (text+ko) ====

@@ -98,13 +98,10 @@
 static const void *usb_temp_get_string_desc(struct usb_device *, uint16_t,
 		    uint8_t);
 static const void *usb_temp_get_vendor_desc(struct usb_device *,
-		    const struct usb_device_request *);
+		    const struct usb_device_request *, uint16_t *plen);
 static const void *usb_temp_get_hub_desc(struct usb_device *);
 static usb_error_t usb_temp_get_desc(struct usb_device *,
 		    struct usb_device_request *, const void **, uint16_t *);
-static usb_error_t usb_temp_setup(struct usb_device *,
-		    const struct usb_temp_device_desc *);
-static void	usb_temp_unsetup(struct usb_device *);
 static usb_error_t usb_temp_setup_by_index(struct usb_device *,
 		    uint16_t index);
 static void	usb_temp_init(void *);
@@ -1035,7 +1032,7 @@
  *------------------------------------------------------------------------*/
 static const void *
 usb_temp_get_vendor_desc(struct usb_device *udev,
-    const struct usb_device_request *req)
+    const struct usb_device_request *req, uint16_t *plen)
 {
 	const struct usb_temp_device_desc *tdd;
 
@@ -1046,7 +1043,7 @@
 	if (tdd->getVendorDesc == NULL) {
 		return (NULL);
 	}
-	return ((tdd->getVendorDesc) (req));
+	return ((tdd->getVendorDesc) (req, plen));
 }
 
 /*------------------------------------------------------------------------*
@@ -1109,7 +1106,6 @@
 		default:
 			goto tr_stalled;
 		}
-		break;
 	case UT_READ_CLASS_DEVICE:
 		switch (req->bRequest) {
 		case UR_GET_DESCRIPTOR:
@@ -1117,11 +1113,6 @@
 		default:
 			goto tr_stalled;
 		}
-		break;
-	case UT_READ_VENDOR_DEVICE:
-	case UT_READ_VENDOR_OTHER:
-		buf = usb_temp_get_vendor_desc(udev, req);
-		goto tr_valid;
 	default:
 		goto tr_stalled;
 	}
@@ -1158,7 +1149,6 @@
 	default:
 		goto tr_stalled;
 	}
-	goto tr_stalled;
 
 tr_handle_get_class_descriptor:
 	if (req->wValue[0]) {
@@ -1168,17 +1158,20 @@
 	goto tr_valid;
 
 tr_valid:
-	if (buf == NULL) {
+	if (buf == NULL)
 		goto tr_stalled;
-	}
-	if (len == 0) {
+	if (len == 0)
 		len = buf[0];
-	}
 	*pPtr = buf;
 	*pLength = len;
 	return (0);	/* success */
 
 tr_stalled:
+	/* try to get a vendor specific descriptor */
+	len = 0;
+	buf = usb_temp_get_vendor_desc(udev, req, &len);
+	if (buf != NULL)
+		goto tr_valid;
 	*pPtr = NULL;
 	*pLength = 0;
 	return (0);	/* we ignore failures */
@@ -1195,7 +1188,7 @@
  *    0: Success
  * Else: Failure
  *------------------------------------------------------------------------*/
-static usb_error_t
+usb_error_t
 usb_temp_setup(struct usb_device *udev,
     const struct usb_temp_device_desc *tdd)
 {
@@ -1285,7 +1278,7 @@
  * This function frees any memory associated with the currently
  * setup template, if any.
  *------------------------------------------------------------------------*/
-static void
+void
 usb_temp_unsetup(struct usb_device *udev)
 {
 	if (udev->usb_template_ptr) {

==== //depot/projects/usb/src/sys/dev/usb/template/usb_template.h#4 (text+ko) ====

@@ -31,7 +31,7 @@
 #define	_USB_TEMPLATE_H_
 
 typedef const void *(usb_temp_get_string_desc_t)(uint16_t lang_id, uint8_t string_index);
-typedef const void *(usb_temp_get_vendor_desc_t)(const struct usb_device_request *req);
+typedef const void *(usb_temp_get_vendor_desc_t)(const struct usb_device_request *req, uint16_t *plen);
 
 struct usb_temp_packet_size {
 	uint16_t mps[USB_SPEED_MAX];
@@ -98,5 +98,8 @@
 extern const struct usb_temp_device_desc usb_template_msc;	/* Mass Storage Class */
 extern const struct usb_temp_device_desc usb_template_mtp;	/* Message Transfer
 								 * Protocol */
+usb_error_t	usb_temp_setup(struct usb_device *,
+		    const struct usb_temp_device_desc *);
+void	usb_temp_unsetup(struct usb_device *);
 
 #endif					/* _USB_TEMPLATE_H_ */

==== //depot/projects/usb/src/sys/dev/usb/template/usb_template_mtp.c#5 (text+ko) ====

@@ -211,7 +211,7 @@
  * Else: Success. Pointer to vendor descriptor is returned.
  *------------------------------------------------------------------------*/
 static const void *
-mtp_get_vendor_desc(const struct usb_device_request *req)
+mtp_get_vendor_desc(const struct usb_device_request *req, uint16_t *plen)
 {
 	static const uint8_t dummy_desc[0x28] = {
 		0x28, 0, 0, 0, 0, 1, 4, 0,


More information about the p4-projects mailing list