From patchwork Wed Sep 16 13:25:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 312430 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp442168ilg; Wed, 16 Sep 2020 06:00:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0Kb4ZgzW8RLpKu6rGH0aw1KRcZm0E2lDPT2S1LUDzhfYeCVFUf0RV9I8OWTE3bmt9yB1E X-Received: by 2002:a17:906:1b04:: with SMTP id o4mr26288883ejg.332.1600261222517; Wed, 16 Sep 2020 06:00:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1600261222; cv=pass; d=google.com; s=arc-20160816; b=gudNYWp45PaFkqwCT706Smzt80TWsLZgOWyCY55wzFZmRp0OzycCutY0LzxjeEpFPl Rc3sFthNMJuhsaoYsMXZQ7vSQxkQ1Lu3kZ9LfuQ+Yz8K+vSnRRopVPXDUB5qRbqth4FU TnHfp8cN+6wlxnFWGYRm35e0bvQj2It+bFra2hOT5Qw4h3nKYWP7g6XUOFpyxkqOeJ01 3Xy+n0Qp47SFGO714lwPAfMQrbJxpEXZL8CuCPsF8llT8kKGFBeuTI7zfPFX8tbNPRBh wKMzP8Y3H3KJjYROGjNJdhZOcbSqAPZyqxu5mA0jJQoetxWKSD4mPrwyr8PgwabgfQp8 g7mA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version :content-transfer-encoding:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=B60Ix4zW4YsPRaUNEWXH06Qy+YHckM980lkxW33FsBA=; b=zDzv4Yd2779c+T5ubMHpu2tmkfPg4g4/E3sMzxcttOU1nNQXLkX91I4AJsy1kUdvXU V695aO7UEMBeeaB8Kkh9/du4ESwFVmMUOQupaA6bHhYIeHhn11DexDWpYSDBB55JgcpK KSmgUo+htYWABq6zb5JbPYpuqJUnTufk9NiLgykIGCHwHI5YNoTsL+tTRFLhw5MDlg8H LW0264A1I9RGcF+MoemyuOa0O3DhV33mgCy6lJZUAYgIE1GN7c0+sJ+EtA/bQp9OrKok ryOBGqERHQDNSz/puYX0nvam1HBlqp+Mo9Z8w4IpuNRZtgOAB8XsbWykla2X0gCEBGqp ZQZQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=mg2ccySc; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id d10si5377568edt.247.2020.09.16.06.00.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Sep 2020 06:00:22 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=mg2ccySc; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A5DD482344; Wed, 16 Sep 2020 14:59:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="mg2ccySc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4FFE38234F; Wed, 16 Sep 2020 14:59:50 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0601.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe1f::601]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C565B82332 for ; Wed, 16 Sep 2020 14:59:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=peng.fan@nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NfdJQi+pF1MTM1/xS6FF5L0CW+D6SolTfIgnHuVz62YTGcHL6LvHccOws8qYlxuC5dk8TzlpXB8C9lYX9fo0ynxmHEvs1ex05N6PwXGjrXCFieQHx6EaCeZaG/tZ830ntr79KTTl1dG4jd1zZYnLBFpJNn/VCeXLpAFE4PQuWFwK0ibL2LX9ZA95Fn6J9i6e/vFoWYvjbMAc+MGwM6QpZWtvqmzwTQ6pNegG8SK2nlqu61bX0gWzs/NKunVrGW+RrgjcdYQWyewhHQySFgsxu6EErPqa1MzNs3q5t33co9SOJ2Vaqy+m8n4btD/CQ7NISheCIFBXT12D9VwfHCHn6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=B60Ix4zW4YsPRaUNEWXH06Qy+YHckM980lkxW33FsBA=; b=TIQROBSJeSYa9DffPClp1UiSh9VFyeR9qUqk+6hYdliZH4H6x9b8JMALkEIgLkBaPOBQb7a4ClfYMTMCsQNyaybDAwXk77HFx3lYmgyjnOOBQgaPaEza5kJrU4uJyWpzlL6T0YbBlGeApg+D0YchjzYqx1jN1cULf9jZlPEXAwGOGz6LkxLgbOm6j56aYbQeBIG5B4aD3Btj0lZQVgWMXuqty39HYsys+hXTDbMqjg1jEFena6punGoO5RvGmb07OGUSQV263VUO/YfY4aJMAkKLbndC7jn+uZrZ01obxKF4JIolMf6EOihiQZoH0koniVPZi1763ES5IXaCSqDOzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=B60Ix4zW4YsPRaUNEWXH06Qy+YHckM980lkxW33FsBA=; b=mg2ccySctzngbXbkMxygGFLL1NOlKq8oLCxRu6ng9p/6Kwn3RHAgc9ps5RwMCDq9+FWbf0FhkOCqUlzn47rJNdY+dLopN8KOK799SJoT1BpwJ10jlH/FQa6lxzqGdK8NX9Ly/pivKJRS14irVM6QxYG+iuXVcdSbtTvMGyxAX2Q= Authentication-Results: denx.de; dkim=none (message not signed) header.d=none;denx.de; dmarc=none action=none header.from=nxp.com; Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) by DB6PR0401MB2373.eurprd04.prod.outlook.com (2603:10a6:4:4b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.18; Wed, 16 Sep 2020 12:59:45 +0000 Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::39ff:13b4:4f28:1413]) by DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::39ff:13b4:4f28:1413%10]) with mapi id 15.20.3370.019; Wed, 16 Sep 2020 12:59:45 +0000 From: peng.fan@nxp.com To: sbabic@denx.de, lukma@denx.de, marex@denx.de Cc: uboot-imx@nxp.com, u-boot@lists.denx.de, Li Jun , Peng Fan Subject: [PATCH 03/16] usb: gadget: OS String support Date: Wed, 16 Sep 2020 21:25:24 +0800 Message-Id: <20200916132537.8313-4-peng.fan@nxp.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200916132537.8313-1-peng.fan@nxp.com> References: <20200916132537.8313-1-peng.fan@nxp.com> X-ClientProxiedBy: SG2PR03CA0131.apcprd03.prod.outlook.com (2603:1096:4:91::35) To DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from linux-1xn6.ap.freescale.net (119.31.174.71) by SG2PR03CA0131.apcprd03.prod.outlook.com (2603:1096:4:91::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.5 via Frontend Transport; Wed, 16 Sep 2020 12:59:43 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [119.31.174.71] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 254ba72f-91ab-4b79-abe2-08d85a40628e X-MS-TrafficTypeDiagnostic: DB6PR0401MB2373: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:849; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w+hb9rj32eLthWHA1YlrQ0S5cg9qo+l1on07XH2juvud0n9GfJti/FTPzSoF9YCc5bAk/ogYWbbTzUVq+gpOJtqW3Llge58y2lbRPvD3+zeYK8XwkwrmHyZAVCH4i78U1BzBx/TTKTUlZE9p7auXFO+4VckKkZdlPNdvkZvf1DF+a4DTXHY+Md45kh7Ovi/9nh31bKLdM9LQpj9O4vhOTYErfEDn34U5A4b5N7zdnd3Hd6DKdgECO0XFtY5ZZngdgcNEMPnzHIi8iMXKpoUtzFWAYMStxH7nwixu+8jxsn2PEMCbJzs+Dwx/YSVQe0lmcCWRtoSURibMtjG/LzF0f3X33tvzaORKDN97/rPa7uLagzftDnW1UUY1+qiVp5aurtsn2rAsAd4HGbfxDLRSDg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB6PR0402MB2760.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(366004)(376002)(136003)(39860400002)(396003)(45080400002)(54906003)(6666004)(9686003)(1076003)(6512007)(5660300002)(478600001)(52116002)(36756003)(6506007)(66946007)(26005)(6486002)(16526019)(186003)(956004)(316002)(66556008)(66476007)(2616005)(86362001)(83380400001)(8936002)(2906002)(4326008)(8676002)(966005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: JMUSP7Vkbipwg07jYf/H35st3me9U4abqkrc7NYKTzF9TaQkaFpNh1bSd9u5wB1gduN7dXRo5Cqt48rp48kWZ7lYNwT6zd++2wM+IQ05cpLlayI4MjmPA+UfF2uzkuAN1Ttuu646KjiXr5EtaIJv0pXhgine9+XBHxhANCYHLd6Z4pITdjLM0kO/qaomqRRjOOrnBQTwIkw35dTSIOA14VAe9ACRl3qBC0tQ13FyPAgnTdU5KM7a8V2Q05LLolV82LfSZtTOyh5lpSv8lZFsle1H9P4XVBYpXE5xQLs1ASvFVn4SgOlYjLzVVytSRW3Qmjm40Fq10OHLGL/MTULEiNwiMcMoohEAuQtgGIfwrfkcbo8CPQtzzMEvq2ft/v06Tq55ezRI6fpTwYkuHPQNOiXE6kHTryBpwKCY65EquTgzNObtYjOLEmAOti2hfQfa28CCuGPH8EsvMuYzzQHsYHDp/+FWlM4ytFcFFAiaFlBXcMJpVtkbo7G/j+4/1KOdJiioFPD+WZA/gCR69L3iuILvw9+QR7ffa430XVav6QPylkDq7Sc61MRL4jifADTUCYmkzZ7aLsccnjAn1kcZ3+uRlzpSrkt9YJTkhJd3psx63ku1D+A1EpoCeXg3mxmtrmVHTOZtYpU8oORvLq2eYQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 254ba72f-91ab-4b79-abe2-08d85a40628e X-MS-Exchange-CrossTenant-AuthSource: DB6PR0402MB2760.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2020 12:59:45.3148 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qT4NFbEtGtb/r4rLUVz7n0kotDefr7pLbvkcG5IbVUumjzxnJDxTqBy0ZLoMVrIUyxmjoG3BTditz3Psv+Gpow== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0401MB2373 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Li Jun 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 Signed-off-by: Peng Fan --- drivers/usb/gadget/composite.c | 26 ++++++++++++++++++++++++++ include/linux/usb/composite.h | 10 ++++++++++ 2 files changed, 36 insertions(+) -- 2.28.0 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;