Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp470738rwb; Thu, 11 Aug 2022 05:02:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR55o+EbeGvBmkFPUYNTMd5JSVajwKKEUkDRox8w1EGXYb+xqhKVmxJ8yaDyB4Vy3QLff2Dw X-Received: by 2002:a05:6402:2b8f:b0:43a:66d4:a025 with SMTP id fj15-20020a0564022b8f00b0043a66d4a025mr30778004edb.121.1660219359947; Thu, 11 Aug 2022 05:02:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660219359; cv=none; d=google.com; s=arc-20160816; b=RzWiHARYfGAjUYnTSXfZthxVJpengi8Nc9DA5wuX3Be2N+sD+cS6d3D1fCgEMkbuIF gLy6pPp+W5foFM6TXT+HJ+ZdNLCrK/PUZ7uzIwyDHpnsHdVJAVvFPuYvokTzf8nO3Gi4 HdFItNl6p2F281NJweW0gjQCaIcZ6j8XmxSJrN/3STdUr9/Obg70yRdp2pZAH65lbyJc 6G1J8ZGLKck5tIR6jc8pamYgDIgArVbe1uttTiYlW8QNNAdCOVff7ZVkkFG07Cjl0D4I GracbnYKpK4cfTqABuBY33lqFQDrARkpmPUm5k7g2IQWtX8c2v424qQqgqK/tYTbLMwx Gexw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=8OQGPoU9xp3+ZsTeJDXhMoZ6cJFPvXYwHVDNuQ1PzqY=; b=RX/AuXt2MONpJLfZq8a2BZ7xA15WISvcu9uWrivP5JbLHS4/L8fJsKUF+BuD0005eF Y9Wbk/U/txuInO9EPqeVKN9bPS/dW6Vctwg2zfq3b1r52XB6g91APrXrGj7ZhHGg2skD OhAWPofm0bq+00AUb4EOf/KB++zLFW9j54UMT2DpmgstnGFnN69tb7ABjors/KY1/etd zpZpkgvBbxXIqUZphs+igZ1LIliCRaMFTSYgJCD9OvHl+a9Nt3GWCQDMcDhtpAemcq0W YI+zNbMGXcH+1VL/0YdDs0rrriBnO4mPAK/rwtceYr4AvkpMz78+MOIX+osUbvGPLttX fV7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bcCI7JE4; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h9-20020a1709067cc900b007307c26f6ddsi6445275ejp.995.2022.08.11.05.02.03; Thu, 11 Aug 2022 05:02:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bcCI7JE4; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235113AbiHKMBa (ORCPT + 99 others); Thu, 11 Aug 2022 08:01:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235100AbiHKMB1 (ORCPT ); Thu, 11 Aug 2022 08:01:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7E2579676D for ; Thu, 11 Aug 2022 05:01:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660219273; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=8OQGPoU9xp3+ZsTeJDXhMoZ6cJFPvXYwHVDNuQ1PzqY=; b=bcCI7JE42FpEvJ2fJR3Yadlr/bwD4kRs/BxtumV2QEbAX6eMUyRjGAEIdjFrXwwm2ihFoJ qhvUcmtnc0iKUkZB6goCxgDqWxfW2IeJsGKIaC3VfI6MBxBapRUpgYpMFP75JVdhDvPPVv kjaX3r2obT/LEOuhQzfB30tMs+YIu5Q= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-360-52AlhS72NSWE0VDk6yWDqA-1; Thu, 11 Aug 2022 08:01:10 -0400 X-MC-Unique: 52AlhS72NSWE0VDk6yWDqA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B6EA29ABA07; Thu, 11 Aug 2022 12:01:09 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.193.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A5652166B26; Thu, 11 Aug 2022 12:01:08 +0000 (UTC) From: Hans de Goede To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: Hans de Goede , linux-bluetooth@vger.kernel.org, Luiz Augusto von Dentz Subject: [PATCH v2] Bluetooth: hci_event: Fix vendor (unknown) opcode status handling Date: Thu, 11 Aug 2022 14:01:03 +0200 Message-Id: <20220811120103.47669-1-hdegoede@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Commit c8992cffbe74 ("Bluetooth: hci_event: Use of a function table to handle Command Complete") was (presumably) meant to only refactor things without any functional changes. But it does have one undesirable side-effect, before *status would always be set to skb->data[0] and it might be overridden by some of the opcode specific handling. While now it always set by the opcode specific handlers. This means that if the opcode is not known *status does not get set any more at all! This behavior change has broken bluetooth support for BCM4343A0 HCIs, the hci_bcm.c code tries to configure UART attached HCIs at a higher baudraute using vendor specific opcodes. The BCM4343A0 does not support this and this used to simply fail: [ 25.646442] Bluetooth: hci0: BCM: failed to write clock (-56) [ 25.646481] Bluetooth: hci0: Failed to set baudrate After which things would continue with the initial baudraute. But now that hci_cmd_complete_evt() no longer sets status for unknown opcodes *status is left at 0. This causes the hci_bcm.c code to think the baudraute has been changed on the HCI side and to also adjust the UART baudrate, after which communication with the HCI is broken, leading to: [ 28.579042] Bluetooth: hci0: command 0x0c03 tx timeout [ 36.961601] Bluetooth: hci0: BCM: Reset failed (-110) And non working bluetooth. Fix this by restoring the previous default "*status = skb->data[0]" handling for unknown opcodes. Fixes: c8992cffbe74 ("Bluetooth: hci_event: Use of a function table to handle Command Complete") Cc: Luiz Augusto von Dentz Signed-off-by: Hans de Goede --- Changes in v2: - Add a comment that byte 0 containing the status is not guaranteed by the Bluetooth specification --- net/bluetooth/hci_event.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index af17dfb20e01..eb43afd5549a 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3996,6 +3996,26 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, void *data, break; } } + if (i == ARRAY_SIZE(hci_cc_table)) { + /* Unknown opcode, assume byte 0 contains the status, so + * that e.g. __hci_cmd_sync() properly returns errors + * for vendor specific commands send by HCI drivers. + * + * Note that the specification does not specify that + * byte 0 is the status: + * + * BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E + * page 2189: + * + * Return_Parameters: + * Size: Depends on command + * + * For now using byte 0 seems to work fine, but in the future + * this may need to be updated so that drivers using vendor + * commands can specify their own completion handler. + */ + *status = skb->data[0]; + } handle_cmd_cnt_and_timer(hdev, ev->ncmd); -- 2.37.1