All of lore.kernel.org
 help / color / mirror / Atom feed
From: peng.fan at nxp.com <peng.fan@nxp.com>
To: u-boot@lists.denx.de
Subject: [PATCH 03/16] usb: gadget: OS String support
Date: Wed, 16 Sep 2020 21:25:24 +0800	[thread overview]
Message-ID: <20200916132537.8313-4-peng.fan@nxp.com> (raw)
In-Reply-To: <20200916132537.8313-1-peng.fan@nxp.com>

From: Li Jun <jun.li@nxp.com>

This is a porting patch from linux kernel: 19824d5eeece
("usb: gadget: OS String support"), original commit log
see below:

"There is a custom (non-USB IF) extension to the USB standard:

http://msdn.microsoft.com/library/windows/hardware/gg463182

They grant permission to use the specification - there is
"Microsoft OS Descriptor Specification License Agreement"
under the link mentioned above, and its Section 2 "Grant
of License", letter (b) reads:

"Patent license. Microsoft hereby grants to You a nonexclusive,
royalty-free, nontransferable, worldwide license under Microsoft?s
patents embodied solely within the Specification and that are owned
or licensable by Microsoft to make, use, import, offer to sell,
sell and distribute directly or indirectly to Your Licensees Your
Implementation. You may sublicense this patent license to Your
Licensees under the same terms and conditions."

The said extension is maintained by Microsoft for Microsoft.

Yet it is fairly common for various devices to use it, and a
popular proprietary operating system expects devices to provide
"OS descriptors", so Linux-based USB gadgets whishing to be able
to talk to a variety of operating systems should be able to provide
the "OS descriptors".

This patch adds optional support for gadgets whishing to expose
the so called "OS String" under index 0xEE of language 0.
The contents of the string is generated based on the qw_sign
array and b_vendor_code.

Interested gadgets need to set the cdev->use_os_string flag,
fill cdev->qw_sign with appropriate values and fill cdev->b_vendor_code
with a value of their choice.

This patch does not however implement responding to any vendor-specific
USB requests."

Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/usb/gadget/composite.c | 26 ++++++++++++++++++++++++++
 include/linux/usb/composite.h  | 10 ++++++++++
 2 files changed, 36 insertions(+)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 91ed7fcec5..63855af52e 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -25,6 +25,22 @@ static inline void le16_add_cpu_packed(__le16_packed *var, u16 val)
 	var->val = cpu_to_le16(le16_to_cpu(var->val) + val);
 }
 
+/**
+ * struct usb_os_string - represents OS String to be reported by a gadget
+ * @bLength: total length of the entire descritor, always 0x12
+ * @bDescriptorType: USB_DT_STRING
+ * @qwSignature: the OS String proper
+ * @bMS_VendorCode: code used by the host for subsequent requests
+ * @bPad: not used, must be zero
+ */
+struct usb_os_string {
+	__u8	bLength;
+	__u8	bDescriptorType;
+	__u8	qwSignature[OS_STRING_QW_SIGN_LEN];
+	__u8	bMS_VendorCode;
+	__u8	bPad;
+} __packed;
+
 /**
  * usb_add_function() - add a function to a configuration
  * @config: the configuration
@@ -577,6 +593,16 @@ static int get_string(struct usb_composite_dev *cdev,
 		return s->bLength;
 	}
 
+	if (cdev->use_os_string && language == 0 && id == OS_STRING_IDX) {
+		struct usb_os_string *b = buf;
+		b->bLength = sizeof(*b);
+		b->bDescriptorType = USB_DT_STRING;
+		memcpy(&b->qwSignature, cdev->qw_sign, sizeof(b->qwSignature));
+		b->bMS_VendorCode = cdev->b_vendor_code;
+		b->bPad = 0;
+		return sizeof(*b);
+	}
+
 	/*
 	 * Otherwise, look up and return a specified string.  String IDs
 	 * are device-scoped, so we look up each string table we're told
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index a49a66f2f8..d4f2a49869 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -284,6 +284,8 @@ struct usb_composite_driver {
 extern int usb_composite_register(struct usb_composite_driver *);
 extern void usb_composite_unregister(struct usb_composite_driver *);
 
+#define OS_STRING_QW_SIGN_LEN		14
+#define OS_STRING_IDX			0xEE
 
 /**
  * struct usb_composite_device - represents one composite usb gadget
@@ -291,6 +293,9 @@ extern void usb_composite_unregister(struct usb_composite_driver *);
  * @req: used for control responses; buffer is pre-allocated
  * @bufsiz: size of buffer pre-allocated in @req
  * @config: the currently active configuration
+ * @qw_sign: qwSignature part of the OS string
+ * @b_vendor_code: bMS_VendorCode part of the OS string
+ * @use_os_string: false by default, interested gadgets set it
  *
  * One of these devices is allocated and initialized before the
  * associated device driver's bind() is called.
@@ -324,6 +329,11 @@ struct usb_composite_dev {
 
 	struct usb_configuration	*config;
 
+	/* OS String is a custom (yet popular) extension to the USB standard. */
+	u8				qw_sign[OS_STRING_QW_SIGN_LEN];
+	u8				b_vendor_code;
+	unsigned int			use_os_string:1;
+
 	/* private: */
 	/* internals */
 	unsigned int			suspended:1;
-- 
2.28.0

  parent reply	other threads:[~2020-09-16 13:25 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-16 13:25 [PATCH 00/16] usb: gadget: update peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 01/16] usb: gadget: Add ep_config call back to usb_gadget_ops peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 02/16] usb: gadget: don't change ep name for dwc3 while ep autoconfig peng.fan at nxp.com
2020-09-16 13:25 ` peng.fan at nxp.com [this message]
2020-09-16 13:25 ` [PATCH 04/16] usb: gadget: move utf8_to_utf16le to header file peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 05/16] usb: gadget: OS Feature Descriptors support peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 06/16] usb: gadget: add WCID support for mfgtool peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 07/16] usb: gadget: fastboot: add ext properties for WCID peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 08/16] usb: gadget: set correct usb_configuration for os_desc_config peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 09/16] usb: gadget: update os_desc_config when add config peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 10/16] usb: gadget: add super speed support peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 11/16] usb: fastboot: " peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 12/16] usb: gadget: dnl: set dnl to be super speed peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 13/16] usb: composite: force gadget to be USB2 for HS only function peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 14/16] usb: udc: ci: update speed handling peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 15/16] usb: gadget: fastboot: use correct max packet size peng.fan at nxp.com
2020-09-16 13:25 ` [PATCH 16/16] usb: gaget: ci: set ep's desc when enable ep peng.fan at nxp.com
2020-10-10  6:00 ` [PATCH 00/16] usb: gadget: update Peng Fan
2021-01-03 10:32   ` Peng Fan
2021-01-23 12:11     ` Lukasz Majewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200916132537.8313-4-peng.fan@nxp.com \
    --to=peng.fan@nxp.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.