Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3220567yba; Tue, 16 Apr 2019 07:08:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXSXHAUerebuN+KZqRgYOSsWrpRb1ZPNo6FcQvVmndnZe1G0lW8vO8kPyom2sAtWyq4aWK X-Received: by 2002:a63:c23:: with SMTP id b35mr75495465pgl.298.1555423726405; Tue, 16 Apr 2019 07:08:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555423726; cv=none; d=google.com; s=arc-20160816; b=tI2Fo8h1K4TpRcM48eVYK5LdnLqWFkxy/sgCX8ms3Z0tssm7U/W0T8ttW/VmAqZ0L8 p0W6gW2wTgw/WWzoO3MP6lIBYDGWf7jrg17sx+wz7aNpONduKet9c7O4toQfLBlXXEjs Kit1lIf/+OgVw5OahTypaZNkIr4KQ3xZiUqdiYP1CbRwONaBLeJlg1WNaGxovyahGw1q JhzXmfXXq1GluhXB7mtiPeEX/4S/1hRqxQsNf4cqzAYklg/fXasBJ0//dVh2kdeSXioa 2UECY91ihn/E56aRLCzAh3tf0DDlG+4ncGJhzbVO2wObuMdl6YZ9gU8IDovHVmoOv8Fl GGMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=2+D4bewqFy4nGLicEOZn/Id12fvAtNwEFAcyOEIgm4I=; b=eL9ldTKbR1Ki2TbejLGZp6ZtOHN1ETiOZX+z41bM0/L3kcbiDhRyEuYsyx0hz2+DKl thNIZmSGyhRjsBiUXnDpTTI7EY0xxcOodgF0vDdxRBprH02yOO3wJ+w/mFvEkYgX3uzX agUFxlmsHtnixUQVRS7qRwx+O5sNcDmdvzdx263z1HGj89PjOM2Ylz7Vs45wFlSjEBAm 1BQyigao3bbdMxxR0cqjYpej+kve5tO8xEIhS/8w+3o+WSYIyAmYB8beBfFsYlIe+64b 40/pOn6YiMHFFDcDbRCQjQLSx42ue1g5DAJ6NsO9YoNd1AM98hG5KMjhcTylG1c+4ZCH E9qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ikd0o67Z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t22si47640136plo.74.2019.04.16.07.08.29; Tue, 16 Apr 2019 07:08:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ikd0o67Z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728297AbfDPOHr (ORCPT + 99 others); Tue, 16 Apr 2019 10:07:47 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44402 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726713AbfDPOHr (ORCPT ); Tue, 16 Apr 2019 10:07:47 -0400 Received: by mail-wr1-f65.google.com with SMTP id y7so27232809wrn.11; Tue, 16 Apr 2019 07:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=2+D4bewqFy4nGLicEOZn/Id12fvAtNwEFAcyOEIgm4I=; b=Ikd0o67ZrKxOaHpUssQg/OnYxGqylkllsNPGtrxJcnLkit4UW56jW+4/EbOSUKwKQH dS8NsY3nLTC+oAModX+id5nPXiuxtVNWmbXFA4o4LhP1xsTND+/EdAoYuRReX8DsKQ+7 HJGChT42xfQwZFBgdkUHYD3zgcKVylkTp0ubKpp8BHl6ZJs9SRe0oN1/05XmgDOarRnF def1zr018F8pYwKaEdlUJR7V403ZLpsDclfIjpv0141MLBdOlJxo/rUp+xehxozjm3Pq XQU84t3teNr/8xeu3GRtJ74afsG4VNDqSsmD2BD2Cppa2kWI5r++czp1eO2l90yT6v/x PiZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=2+D4bewqFy4nGLicEOZn/Id12fvAtNwEFAcyOEIgm4I=; b=VPNVvMKaeSE2kXHUxlGxamAch5DJWwey91eVzoHku88QWovXPt6HfHxlRkyytZWZ3Q Og0th2aUYDh5Tv8GLGIQnJ4dIwrpU/TSVk31KaO8PAZZSqLlOmOByuFys5G7+fMqDQug cYZ1O26rNY5i6DZKr98mG49KsdXm0hrC/UH+93m0ZPlXsUcOj00Ha8RQ8y8Vyr2skGal K0quxLaO2pFgMVH3j91p/1L4Z0u9ttCvWpHXDOZAwMFH5hX+4qsbhYLex+D5Z14tuUEi ZSXMpYTCsdHZefLaPmIthPkJAZL6jkQOitW01ZcOP7Wdl/wxpQ9igWiR7OeIqYnJza0V 9fMA== X-Gm-Message-State: APjAAAXm0a/76DPjgnEi94Di3lwl1n7Qh3UmNwZ0xc0al4dCnkxjENTW Q8vACSJzRNYcE/QfRNd3OcQ= X-Received: by 2002:a5d:424b:: with SMTP id s11mr43565750wrr.158.1555423666052; Tue, 16 Apr 2019 07:07:46 -0700 (PDT) Received: from 5WDYG62.mdi (static-css-cqn-143221.business.bouyguestelecom.com. [176.149.143.221]) by smtp.gmail.com with ESMTPSA id v192sm24008494wme.24.2019.04.16.07.07.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Apr 2019 07:07:45 -0700 (PDT) From: Romain Izard To: Felipe Balbi , Greg Kroah-Hartman , Andrzej Pietrasiewicz Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Romain Izard Subject: [PATCH 1/2] usb: gadget: f_ncm: Fix NTP-32 support Date: Tue, 16 Apr 2019 16:07:31 +0200 Message-Id: <20190416140732.21941-1-romain.izard.pro@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When connecting a CDC-NCM gadget to an host that uses the NTP-32 mode, or that relies on the default CRC setting, the current implementation gets confused, and does not expect the correct signature for its packets. Fix this, by ensuring that the ndp_sign member in the f_ncm structure always contain a valid value. Signed-off-by: Romain Izard --- drivers/usb/gadget/function/f_ncm.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c index 5780fba620ab..d5c47e7a7f61 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -35,9 +35,7 @@ /* to trigger crc/non-crc ndp signature */ -#define NCM_NDP_HDR_CRC_MASK 0x01000000 #define NCM_NDP_HDR_CRC 0x01000000 -#define NCM_NDP_HDR_NOCRC 0x00000000 enum ncm_notify_state { NCM_NOTIFY_NONE, /* don't notify */ @@ -526,6 +524,7 @@ static inline void ncm_reset_values(struct f_ncm *ncm) { ncm->parser_opts = &ndp16_opts; ncm->is_crc = false; + ncm->ndp_sign = ncm->parser_opts->ndp_sign; ncm->port.cdc_filter = DEFAULT_FILTER; /* doesn't make sense for ncm, fixed size used */ @@ -805,25 +804,20 @@ static int ncm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8) | USB_CDC_SET_CRC_MODE: { - int ndp_hdr_crc = 0; - if (w_length != 0 || w_index != ncm->ctrl_id) goto invalid; switch (w_value) { case 0x0000: ncm->is_crc = false; - ndp_hdr_crc = NCM_NDP_HDR_NOCRC; DBG(cdev, "non-CRC mode selected\n"); break; case 0x0001: ncm->is_crc = true; - ndp_hdr_crc = NCM_NDP_HDR_CRC; DBG(cdev, "CRC mode selected\n"); break; default: goto invalid; } - ncm->ndp_sign = ncm->parser_opts->ndp_sign | ndp_hdr_crc; value = 0; break; } @@ -840,6 +834,8 @@ static int ncm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) ctrl->bRequestType, ctrl->bRequest, w_value, w_index, w_length); } + ncm->ndp_sign = ncm->parser_opts->ndp_sign | + (ncm->is_crc ? NCM_NDP_HDR_CRC : 0); /* respond with data transfer or status phase? */ if (value >= 0) { -- 2.17.1