From patchwork Mon Jan 25 13:43:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 370224 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp3992519jam; Mon, 25 Jan 2021 05:27:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYXC2eEIU2R5IxgAYt+JXQp43caFdZAzZSxMzC6tgx7gEtflIEMYi1HycCM2CY37Jcu+uc X-Received: by 2002:aa7:db1a:: with SMTP id t26mr474439eds.25.1611581239177; Mon, 25 Jan 2021 05:27:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1611581239; cv=pass; d=google.com; s=arc-20160816; b=eDM9ogCBXssD4nKvF4ae2dsKYg0dHZp5NYdH5fXa5/Rp2tJi1oG/KgHkWjTDk56dmg HD6LYkUcpThamqNFisFDT9G/R70k8UsEho0rogZIz2pua3lnnw44Dld75Oia/xO51vZb d8yNSoxhFVC6d8riNhEJHl/wUsP7u5LEACpq3nCBYBaM6/6LRIWtxrlI7BItX8MMfuLl o4gh6z4GB25uIdNfzGiszLMG7M2wRu58JcOFMSbRKyTswpTXjNByI4cNDnEAAsNWA0wW kKJDWSGEchw0yOVRXky5+E4C6t9DhMagBqvfcDr4BmwihSQ4JOB7C8WnLmHPvvuzoMjJ Jmfw== 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=C3kN8UVs7NkJBkzyDtHEFIywoCCPoZ3tryN8+Ofcai0=; b=pprJkPP5KyYf+ewvb9zxwYIISnswKt3x/fnUO8d301DdrT2ZGnZJPJodv6yqrqOHhN JJkfxscZQD3ZaVxOQCb48vNFQMYq1JYZJYXrppiTv8DdAP4upC0NRvANmfvlRTuDCgJ5 olfx0ta+85J4tFkLKeT0KTt0325f5R6buSVnHvzUWuORdqSArsVDXGcqFq3LeeIvLpan /G3ZrT5kQNcpPb87JS4dyRS77uXrziqPXkH77I2/tZJkI4UAT1iovYfrxy6UkUV3nM3E UqbBGZTWn56GJdXwbadyU3VEzKv4MTWQjaBuOwBLZyJAvXcYfHTLp4Y+hVSgpOox/IgX ZbFA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=sKYfqsJc; 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 dk25si7079471edb.583.2021.01.25.05.27.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jan 2021 05:27:19 -0800 (PST) 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=sKYfqsJc; 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 AF2C282709; Mon, 25 Jan 2021 14:26:34 +0100 (CET) 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="sKYfqsJc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3C53982679; Mon, 25 Jan 2021 14:14:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-ve1eur02on0619.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe06::619]) (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 D07EB8267A for ; Mon, 25 Jan 2021 14:14:39 +0100 (CET) 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=PlbHh0eGASmPkzmMM2jp+iWhGXNh8VhAZEu9HrkvW2kt0vuNy/Hl/EgKxy1EAbekDp0iM9MSNV6UUDQETPnckSpTwn2NKS7C03tWInFy5AiRLqyE+aLSP7+0qFKgvA1BTTUBSWZAoWkIfuiUAjeGcZ+HLVQIhB6mTxaazK9Mbdx841X2MyG4UOmam9qpqjYz/J8iSBDn1PodujoOXDYcJ7wyDK+y22b3XnaFwfKjd9LHw+PcbuZFCTH6qhCw0aaGFtNJpfZSqqnAprqhcn1ET3CV0vLecYxsWvucYGEib6OGEuSqMT+MaQEGtNljlWdE7aUyGCZ2VmyNNuetHqlCoQ== 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=C3kN8UVs7NkJBkzyDtHEFIywoCCPoZ3tryN8+Ofcai0=; b=hU03di8ZzPfNFJMf/2qRC6pEAv75YejCPrvJz4Q8rpsi30ai/O9KorkAonF/V3CEduQ+3jjEgFWT6A5M/05Lopmi3NFO+xLw8ghG33IltGwFUwvH3RwpCYXefZ26b9HPv3hpc8naE0SnYxa0JF1leeD8DaQRFizP4lSAsPR2VSyT1eNZrjJY61bgbm6zTkAdF8xMlCw3C0/ciL0LmECJvPde2h8+GSawn04rymKXG0hxEIXPQY1OXa8oCxm46h6BeFP4WuKHrMWMDoRoiyXkEEKAirof2bZGhDkwQCkrsurJ/9Lh2YimnTH5amk/xjKGYxUsh0EIQYMogs1coNYTmQ== 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=C3kN8UVs7NkJBkzyDtHEFIywoCCPoZ3tryN8+Ofcai0=; b=sKYfqsJcStpWpFH29zbO2B9dNyASrqaRmPOVlt0VZkWOHpPHWTl7HXOEvc4Vw1TufVaaXqd0x4Ej/LufjmDRyQwCa+W7MzX+1JFeVZp+g3dvqkBJ3oUZkMFh5OLqVsorWB8OaIWYZj8kWsuL2DJbBOFVgMc3FlbxvWX2xP1LZaE= 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 DBBPR04MB7930.eurprd04.prod.outlook.com (2603:10a6:10:1ea::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.17; Mon, 25 Jan 2021 13:14:38 +0000 Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::d58c:d479:d094:43d0]) by DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::d58c:d479:d094:43d0%9]) with mapi id 15.20.3784.019; Mon, 25 Jan 2021 13:14:38 +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 V2 03/17] usb: gadget: OS String support Date: Mon, 25 Jan 2021 21:43:46 +0800 Message-Id: <20210125134400.780-4-peng.fan@nxp.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210125134400.780-1-peng.fan@nxp.com> References: <20210125134400.780-1-peng.fan@nxp.com> X-Originating-IP: [119.31.174.71] X-ClientProxiedBy: SG2PR03CA0117.apcprd03.prod.outlook.com (2603:1096:4:91::21) 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 SG2PR03CA0117.apcprd03.prod.outlook.com (2603:1096:4:91::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.6 via Frontend Transport; Mon, 25 Jan 2021 13:14:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7793be70-3071-4212-8b6c-08d8c1332b34 X-MS-TrafficTypeDiagnostic: DBBPR04MB7930: 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: P/h3VTOpohE8livAcL/BLjFK3ZDwifiVGAv01hFpEAeqqvRvd9TIouhfYEjW6Z16Hd6W/wD4FElWUcrn63ofrA4uUA/kYw9udpC21MQTxhCxBTGZ0FXs854XShSy60id8D/pXDpjoL3i/rPg76/l7EaRpg/UpGkoHijvVtPpIG3MEWdKlXoNwfbT/LsTrSGOsgdIRAI+fjeQ3qUb34kZnsQ/vP5DDWScAj5MVi1CMXiAcqaybJFhMKQm0u4JwuVcYJ2tA1jSXc/AfLPOGaBqbgPQx0G51DijZMqXGapQArsigPhuglsBZfazb01qKWoUw+zfFDp4CCcf+nogu4NNWEhoTNbp+jmjvpUuX7isHc2UVjd7Rfw/lUV+gPLu8k0QnUM727NPOlJaIEy/v8EAyDbjHb96b1bDlaxKGKfyX+CcqoL+lA51aVT3lxqn99Z53WgfndH7d8uwxvHpLSVQ5g== 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)(366004)(396003)(346002)(39860400002)(376002)(136003)(2906002)(66476007)(66556008)(8936002)(186003)(4326008)(16526019)(83380400001)(8676002)(966005)(478600001)(45080400002)(66946007)(5660300002)(6666004)(9686003)(2616005)(36756003)(54906003)(1076003)(956004)(6512007)(6486002)(6506007)(86362001)(316002)(52116002)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?4qq7ErjwF/J9kRZTR1PC73oCPaS?= =?utf-8?q?6OTX3uy4wwRsQDbwS9g4E1jL5otEq6kh5fS2DHPi+wiSHw3OjpcFWeTS?= =?utf-8?q?877lksHRoOmCUU8KAdwmZmONMYNj4JVcM/o1zNjb5xClXxSEoCgbrclf?= =?utf-8?q?eVFjAO2aN1rFG0LJ8H25QBF5idWBoggOCimoGGNol9koJcdDyOM2/cso?= =?utf-8?q?BWjAh+Tj0GbI5h1q1dlhAxN2wX6fq9aEnlTHjvO8IckAt09rs/T9yER5?= =?utf-8?q?//0uy3o9YwxEwspjngs3H7P1e4gDZwcvojHCYUgP9Giv7qBpEzy1Hvd6?= =?utf-8?q?/Y3tWOGLq8rO64V33tV/uNqIlAj5CBAMekMNaihibM0VEs7t1ys8BkoS?= =?utf-8?q?9ePj4Pp3oi+sjRw75XXcv0IDLoJ1fReHFOID2IRGKq/TDm+1Z/n19SjR?= =?utf-8?q?LUpEw1XZEwK+AkvpPM4joB3D2uIw6kE6GygTfRLEu7mI2szG6DRzBpuO?= =?utf-8?q?1DB12gPJpHlhBaxmupyk+PU7N2nFO7C/23yBQ4Fqe/AjEthy/pVn5isI?= =?utf-8?q?FWbMLAxahLS7uslw2q7eGEqz7yNGFn8twIBDnjOknG2Z5QwTQmyQ36GP?= =?utf-8?q?oMGb1muFLaU/Rl5fCDRlb/2A08LTNvVd2pa/JYHc4bBHqcaQc4w4ZGKR?= =?utf-8?q?HSD3kcuTk/kMO4olAy/jiiJNJjwVJLwVPXhTqvh9RTsvYpgVv2WlHUt6?= =?utf-8?q?7SxUfPd7z13uknBwUFtgz3qma9qZXtBoe5/uKiZtXV36UFaApU5XiqNV?= =?utf-8?q?qp3T0qfh4fQLgVQS0AaeftaDdn1RcZhcREFKAjiek4DS/qKiiq1EHyrY?= =?utf-8?q?aI0wEPo3elA4IAdm/vE+Lgua2LH9pMHw11hn0cfiUGirKrWnr52B3SS7?= =?utf-8?q?yH+e0JZ4OO5hYa9i8m3rAjMYH+lS5vZ1ZAHBtYQ7Z+0SNWrTY1Vw/ZTi?= =?utf-8?q?w6OG+JrUwOe1g8YlAyAwGrD7P+v9+CBVLNeEhXkHvK9sTRNgZUSkmloB?= =?utf-8?q?e4cSpffDZEzDNXt34ynPs+a9RcKxVr5AEfyFf0dUzEsCi?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7793be70-3071-4212-8b6c-08d8c1332b34 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0402MB2760.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2021 13:14:38.8790 (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: 2HGjqv4Vki8en6R4Q5bhZ8Aghp7SnUrvBVX3f+aagCKNFwYdkmOGDf9iwm9Svxch4we+rW8hjvty1EsG/JpdKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7930 X-Mailman-Approved-At: Mon, 25 Jan 2021 14:26:22 +0100 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鈥檚 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;