[RFC/PATCH 09/12] usb: gadget: composite: handle GetDescriptor(BOS)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



case host is asking for a BOS descriptor, we need
to it them if we have.

Signed-off-by: Felipe Balbi <balbi@xxxxxx>
---
 drivers/usb/gadget/composite.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 5fe5b88..04d3e1f 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -617,6 +617,34 @@ static int lookup_string(
 	return -EINVAL;
 }
 
+static int get_bos_descriptor(struct usb_composite_dev *cdev,
+		void *buf)
+{
+	struct usb_bos_descriptor	*bos = cdev->bos;
+	const struct usb_dev_cap_header	*cap;
+	int				len = USB_BUFSIZ;
+	void				*next = buf;
+
+	if (!cdev->bos)
+		return -EINVAL;
+
+	if (!cdev->capabilities)
+		return -EINVAL;
+
+	memcpy(next, bos, bos->bLength);
+	next += bos->bLength;
+	len -= bos->bLength;
+
+	for (cap = *cdev->capabilities; cap; cap++) {
+		bos->bNumDeviceCaps++;
+		memcpy(next, cap, cap->bLength);
+		next += cap->bLength;
+		len -= cap->bLength;
+	}
+
+	return len;
+}
+
 static int get_string(struct usb_composite_dev *cdev,
 		void *buf, u16 language, int id)
 {
@@ -870,6 +898,9 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 			if (value >= 0)
 				value = min(w_length, (u16) value);
 			break;
+		case USB_DT_BOS:
+			value = get_bos_descriptor(cdev, req->buf);
+			break;
 		}
 		break;
 
@@ -1137,6 +1168,9 @@ static int composite_bind(struct usb_gadget *gadget)
 	cdev->desc = *composite->dev;
 	cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
 
+	cdev->bos = composite->bos;
+	cdev->capabilities = composite->capabilities;
+
 	/* standardized runtime overrides for device ID data */
 	if (idVendor)
 		cdev->desc.idVendor = cpu_to_le16(idVendor);
-- 
1.7.4.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux