Author: thompsa
Date: Thu Mar 11 21:45:31 2010
New Revision: 205030
URL: http://svn.freebsd.org/changeset/base/205030

Log:
  - 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.
  
  Submitted by: Hans Petter Selasky

Modified:
  head/sys/dev/usb/template/usb_template.c
  head/sys/dev/usb/template/usb_template.h
  head/sys/dev/usb/template/usb_template_mtp.c

Modified: head/sys/dev/usb/template/usb_template.c
==============================================================================
--- head/sys/dev/usb/template/usb_template.c    Thu Mar 11 21:42:09 2010        
(r205029)
+++ head/sys/dev/usb/template/usb_template.c    Thu Mar 11 21:45:31 2010        
(r205030)
@@ -98,13 +98,10 @@ static void *usb_temp_get_config_desc(st
 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 @@ usb_temp_get_config_desc(struct usb_devi
  *------------------------------------------------------------------------*/
 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 @@ usb_temp_get_vendor_desc(struct usb_devi
        if (tdd->getVendorDesc == NULL) {
                return (NULL);
        }
-       return ((tdd->getVendorDesc) (req));
+       return ((tdd->getVendorDesc) (req, plen));
 }
 
 /*------------------------------------------------------------------------*
@@ -1109,7 +1106,6 @@ usb_temp_get_desc(struct usb_device *ude
                default:
                        goto tr_stalled;
                }
-               break;
        case UT_READ_CLASS_DEVICE:
                switch (req->bRequest) {
                case UR_GET_DESCRIPTOR:
@@ -1117,11 +1113,6 @@ usb_temp_get_desc(struct usb_device *ude
                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 @@ tr_handle_get_descriptor:
        default:
                goto tr_stalled;
        }
-       goto tr_stalled;
 
 tr_handle_get_class_descriptor:
        if (req->wValue[0]) {
@@ -1168,17 +1158,20 @@ tr_handle_get_class_descriptor:
        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 @@ tr_stalled:
  *    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 @@ error:
  * 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) {

Modified: head/sys/dev/usb/template/usb_template.h
==============================================================================
--- head/sys/dev/usb/template/usb_template.h    Thu Mar 11 21:42:09 2010        
(r205029)
+++ head/sys/dev/usb/template/usb_template.h    Thu Mar 11 21:45:31 2010        
(r205030)
@@ -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
 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_ */

Modified: head/sys/dev/usb/template/usb_template_mtp.c
==============================================================================
--- head/sys/dev/usb/template/usb_template_mtp.c        Thu Mar 11 21:42:09 
2010        (r205029)
+++ head/sys/dev/usb/template/usb_template_mtp.c        Thu Mar 11 21:45:31 
2010        (r205030)
@@ -211,7 +211,7 @@ const struct usb_temp_device_desc usb_te
  * 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,
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to