summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthompsa <thompsa@FreeBSD.org>2010-03-11 21:45:31 +0000
committerthompsa <thompsa@FreeBSD.org>2010-03-11 21:45:31 +0000
commitec6f68895e11fc686715e9a97132c7334f846214 (patch)
treec969a52256338f3d50b0b5f41215790804dde7a8
parent13649bde8d5a3f79c891ff09f71387b4c9d244c1 (diff)
downloadFreeBSD-src-ec6f68895e11fc686715e9a97132c7334f846214.zip
FreeBSD-src-ec6f68895e11fc686715e9a97132c7334f846214.tar.gz
- 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
-rw-r--r--sys/dev/usb/template/usb_template.c31
-rw-r--r--sys/dev/usb/template/usb_template.h5
-rw-r--r--sys/dev/usb/template/usb_template_mtp.c2
3 files changed, 17 insertions, 21 deletions
diff --git a/sys/dev/usb/template/usb_template.c b/sys/dev/usb/template/usb_template.c
index d3271b2..be45ed9 100644
--- a/sys/dev/usb/template/usb_template.c
+++ b/sys/dev/usb/template/usb_template.c
@@ -98,13 +98,10 @@ static void *usb_temp_get_config_desc(struct usb_device *, uint16_t *,
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_device *udev,
*------------------------------------------------------------------------*/
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_device *udev,
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 *udev, struct usb_device_request *req,
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 *udev, struct usb_device_request *req,
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) {
diff --git a/sys/dev/usb/template/usb_template.h b/sys/dev/usb/template/usb_template.h
index cc9ca0c..2473af3 100644
--- a/sys/dev/usb/template/usb_template.h
+++ b/sys/dev/usb/template/usb_template.h
@@ -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_cdce;
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_ */
diff --git a/sys/dev/usb/template/usb_template_mtp.c b/sys/dev/usb/template/usb_template_mtp.c
index a98a242..40da823 100644
--- a/sys/dev/usb/template/usb_template_mtp.c
+++ b/sys/dev/usb/template/usb_template_mtp.c
@@ -211,7 +211,7 @@ const struct usb_temp_device_desc usb_template_mtp = {
* 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,
OpenPOWER on IntegriCloud