From patchwork Tue Oct 9 14:43:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Pelletier X-Patchwork-Id: 10632835 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB01C16B1 for ; Tue, 9 Oct 2018 14:43:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 957B527FA5 for ; Tue, 9 Oct 2018 14:43:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87ED228A03; Tue, 9 Oct 2018 14:43:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DBE327FA5 for ; Tue, 9 Oct 2018 14:43:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726479AbeJIWAm (ORCPT ); Tue, 9 Oct 2018 18:00:42 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37940 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726393AbeJIWAm (ORCPT ); Tue, 9 Oct 2018 18:00:42 -0400 Received: by mail-pf1-f194.google.com with SMTP id f29-v6so962992pff.5 for ; Tue, 09 Oct 2018 07:43:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=c1aSOiYNbzKeYGNqaeknpRe7nMfW1u3uDo5kLAg9OfQ=; b=gSYPgHbklaKziMP+3vR5vjI18UqDSpUkyetkmeGb6ePXKd6pMn1hwPNjVWnjzNhwzG gvQRFY7+qHbnPuU66/r6YGs22u7nm6ynZmOPl7iPpO5hw2rUIoq8m91yZfhEZonvPsXB 67V/nJpBFpFnsY++EpqLGwgoiQ5Uzi6LoFPh3zd9sZs5XMHaRcOjuoAqJTCkfHbHWGQc XeQ3FAIMwQHBkTwDzxa+lwoZvj0Bf46YapbukAZIWm7tpaEvvHOa+kezD8aG20h5q0Su 8//kDS51rWX8eSOs4FH882SfLwHuEDyZI2SNwFUJ6Ui/3Pl/H3EQo2Ms8I4xdv5cFSaa c2WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=c1aSOiYNbzKeYGNqaeknpRe7nMfW1u3uDo5kLAg9OfQ=; b=OqRV7ls2ntBng0SWdi+7m1jhKNinp3V7fIZybLs/PMzYiL/e7aYKdewNkeZjN9bHA3 DS9niwgwwq3EKMUfKYXkGTryQBGSUEVN1fPwtSvFmEQJJiTYjsAVnwLlKgDSLbRq/ede 0s49FbwkGFGhpL6o8fGvQQqGX6SiGmPtepr6Hfb6zgH7HG3jQX/ybbcS4QjGkUTB7gSF ZEplNbz5bz6iOfsxCOF/vL1ocCcFJbjrr9oQ97fdevPKV8AAZayBzwH+W1iTwkJZ4EEE ZRKdtikzZ+s1LKNEjAoZcWt7JsNCl/KaYPL50sYUzsObVUhYQUPBigOdwz6Bx92hUEX1 sDPA== X-Gm-Message-State: ABuFfojV7fL9pAlYhfVZ6wmy2EjiTP7yypm6KYSPAkD/e1v8eOc3vNf6 D/F56EPFYx/jwSk3KTfDkxc= X-Google-Smtp-Source: ACcGV60hRl+VfOI/4LzW7/pp+vKdpmfZELmawU2ZyBb3cGyCYetny90EUtl+0XIXdSZksQacbUxozg== X-Received: by 2002:a63:4e4e:: with SMTP id o14-v6mr26568626pgl.181.1539096205811; Tue, 09 Oct 2018 07:43:25 -0700 (PDT) Received: from x2.lan ([2400:406d:175b:7500::7d4b]) by smtp.gmail.com with ESMTPSA id 22-v6sm29234673pfl.126.2018.10.09.07.43.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 07:43:25 -0700 (PDT) From: Vincent Pelletier To: Felipe Balbi , linux-usb@vger.kernel.org Subject: usb: gadget: f_fs: Add support for CCID descriptors. Date: Tue, 9 Oct 2018 14:43:18 +0000 Message-Id: <896f8db53f8977fe18238747f1161634946c2010.1539096198.git.plr.vincent@gmail.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Nothing to remap, only check length. Define a minimal structure for CCID descriptor only used to check length. As this descriptor shares the same value as HID descriptors, keep track and compare current interface's class to expected HID and CCID standard values. Signed-off-by: Vincent Pelletier --- drivers/usb/gadget/function/f_fs.c | 29 +++++++++++++---- include/linux/usb/ccid.h | 51 ++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 include/linux/usb/ccid.h diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 3ada83d81bda..258afccb4627 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -1936,7 +1937,7 @@ typedef int (*ffs_os_desc_callback)(enum ffs_os_desc_type entity, static int __must_check ffs_do_single_desc(char *data, unsigned len, ffs_entity_callback entity, - void *priv) + void *priv, int *current_class) { struct usb_descriptor_header *_ds = (void *)data; u8 length; @@ -1994,6 +1995,7 @@ static int __must_check ffs_do_single_desc(char *data, unsigned len, __entity(INTERFACE, ds->bInterfaceNumber); if (ds->iInterface) __entity(STRING, ds->iInterface); + *current_class = ds->bInterfaceClass; } break; @@ -2007,11 +2009,22 @@ static int __must_check ffs_do_single_desc(char *data, unsigned len, } break; - case HID_DT_HID: - pr_vdebug("hid descriptor\n"); - if (length != sizeof(struct hid_descriptor)) - goto inv_length; - break; + case USB_TYPE_CLASS | 0x01: + if (*current_class == USB_INTERFACE_CLASS_HID) { + pr_vdebug("hid descriptor\n"); + if (length != sizeof(struct hid_descriptor)) + goto inv_length; + break; + } else if (*current_class == USB_INTERFACE_CLASS_CCID) { + pr_vdebug("ccid descriptor\n"); + if (length != sizeof(struct ccid_descriptor)) + goto inv_length; + break; + } else { + pr_vdebug("unknown descriptor: %d for class %d\n", + _ds->bDescriptorType, *current_class); + return -EINVAL; + } case USB_DT_OTG: if (length != sizeof(struct usb_otg_descriptor)) @@ -2068,6 +2081,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, { const unsigned _len = len; unsigned long num = 0; + int current_class = -1; ENTER(); @@ -2088,7 +2102,8 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, if (!data) return _len - len; - ret = ffs_do_single_desc(data, len, entity, priv); + ret = ffs_do_single_desc(data, len, entity, priv, + ¤t_class); if (unlikely(ret < 0)) { pr_debug("%s returns %d\n", __func__, ret); return ret; diff --git a/include/linux/usb/ccid.h b/include/linux/usb/ccid.h new file mode 100644 index 000000000000..3431446d6864 --- /dev/null +++ b/include/linux/usb/ccid.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2018 Vincent Pelletier + */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __CCID_H +#define __CCID_H + +#include + +#define USB_INTERFACE_CLASS_CCID 0x0b + +struct ccid_descriptor { + __u8 bLength; + __u8 bDescriptorType; + __le16 bcdCCID; + __u8 bMaxSlotIndex; + __u8 bVoltageSupport; + __le32 dwProtocols; + __le32 dwDefaultClock; + __le32 dwMaximumClock; + __u8 bNumClockSupported; + __le32 dwDataRate; + __le32 dwMaxDataRate; + __u8 bNumDataRatesSupported; + __le32 dwMaxIFSD; + __le32 dwSynchProtocols; + __le32 dwMechanical; + __le32 dwFeatures; + __le32 dwMaxCCIDMessageLength; + __u8 bClassGetResponse; + __u8 bClassEnvelope; + __le16 wLcdLayout; + __u8 bPINSupport; + __u8 bMaxCCIDBusySlots; +} __attribute__ ((packed)); + +#endif /* __CCID_H */