Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b670228 authored by Vijayavardhan Vennapusa's avatar Vijayavardhan Vennapusa Committed by Stephen Boyd
Browse files

USB: gadget: composite: Process GetDescriptor(OTG) request



If gadget is OTG capable, respond to a GetDescriptor(OTG) request
with its OTG descriptor.  This patch adds a utility to function
to find and fill the requested descriptor.

Change-Id: I5b3624b1145d46179b0c4737e82a47c68604cab4
Signed-off-by: default avatarPavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: default avatarVijayavardhan Vennapusa <vvreddy@codeaurora.org>
parent 0884e68d
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -1226,6 +1226,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
	u16				w_length = le16_to_cpu(ctrl->wLength);
	struct usb_function		*f = NULL;
	u8				endp;
	struct usb_configuration *c;

	/* partial re-init of the response message; the function or the
	 * gadget might need to intercept e.g. a control-OUT completion
@@ -1279,6 +1280,17 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
			if (value >= 0)
				value = min(w_length, (u16) value);
			break;
		case USB_DT_OTG:
			if (!gadget_is_otg(gadget))
				break;
			c = list_first_entry(&cdev->configs,
				struct usb_configuration, list);
			if (c && c->descriptors)
				value = usb_find_descriptor_fillbuf(req->buf,
						USB_COMP_EP0_BUFSIZ,
						c->descriptors,
						USB_DT_OTG);
			break;
		case USB_DT_STRING:
			value = get_string(cdev, req->buf,
					w_index, w_value & 0xff);
+35 −0
Original line number Diff line number Diff line
@@ -21,6 +21,41 @@
#include <linux/usb/gadget.h>
#include <linux/usb/composite.h>

/**
 * usb_find_descriptor_fillbuf - fill buffer with the requested descriptor
 * @buf: Buffer to be filled
 * @buflen: Size of buf
 * @src: Array of descriptor pointers, terminated by null pointer.
 * @desc_type: bDescriptorType field of the requested descriptor.
 *
 * Copies the requested descriptor into the buffer, returning the length
 * or a negative error code if it is not found or can't be copied.  Useful
 * when DT_OTG descriptor is requested.
 */
int
usb_find_descriptor_fillbuf(void *buf, unsigned buflen,
		const struct usb_descriptor_header **src, u8 desc_type)
{
	if (!src)
		return -EINVAL;

	for (; NULL != *src; src++) {
		unsigned len;

		if ((*src)->bDescriptorType != desc_type)
			continue;

		len = (*src)->bLength;
		if (len > buflen)
			return -EINVAL;

		memcpy(buf, *src, len);
		return len;
	}

	return -ENOENT;
}

/**
 * usb_descriptor_fillbuf - fill buffer with descriptors
 * @buf: Buffer to be filled
+5 −0
Original line number Diff line number Diff line
@@ -931,6 +931,11 @@ int usb_gadget_get_string(struct usb_gadget_strings *table, int id, u8 *buf);

/* utility to simplify managing config descriptors */

/* Find and fill the requested descriptor into buffer */
int
usb_find_descriptor_fillbuf(void *, unsigned,
		const struct usb_descriptor_header **, u8);

/* write vector of descriptors into buffer */
int usb_descriptor_fillbuf(void *, unsigned,
		const struct usb_descriptor_header **);