- 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
This commit is contained in:
Andrew Thompson 2010-03-11 21:45:31 +00:00
parent 8817f29901
commit 9a8e0122d2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=205030
3 changed files with 17 additions and 21 deletions

View File

@ -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 @@ usb_temp_get_desc(struct usb_device *udev, struct usb_device_request *req,
default:
goto tr_stalled;
}
goto tr_stalled;
tr_handle_get_class_descriptor:
if (req->wValue[0]) {
@ -1168,17 +1158,20 @@ usb_temp_get_desc(struct usb_device *udev, struct usb_device_request *req,
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 @@ usb_temp_get_desc(struct usb_device *udev, struct usb_device_request *req,
* 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 @@ usb_temp_setup(struct usb_device *udev,
* 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) {

View File

@ -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_ */

View File

@ -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,