Received: by 2002:a05:6359:322:b0:b3:69d0:12d8 with SMTP id ef34csp93034rwb; Wed, 10 Aug 2022 15:31:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR6JSUOqZakrMgPK6WabcqHaWRCunf8skLrNDbHBi0DK+H5LWuViFyb3VLpf43zdh35KY4h+ X-Received: by 2002:a17:907:2c48:b0:730:cdc9:2c0b with SMTP id hf8-20020a1709072c4800b00730cdc92c0bmr22107876ejc.482.1660170715306; Wed, 10 Aug 2022 15:31:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660170715; cv=none; d=google.com; s=arc-20160816; b=Jd/BgjaFpkoXO0AwxZhELgcbAnzknbAPvCjInEI5wlHes8/UQNG2deGugd4lmDRbsQ PRalDDWdkJs/U5zrTXbeCHwskqdGMgSHq7/milKPedF0a4eVXvoIliQcCUI3ywRE53TZ qFp0KefWTvVM/L1FEfHZn2lH45GFAt0kD1/NVuCfuoklLYjiPkiAiVI+tdvlOQ0cG+Et aszUWrtADA7+XsPKYHJb4Qh9PC79BNu4jgbABtFcbkqHgiWLq7JOSKqXXPTKeciuwg9o daJSvB+bNE9RTlG2imF6BLf6D8pRGJfe9nLhBGlx4Zqg0YhMlZwYY5VwpdEVMFMiuINi dL8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Igs1I7eqEMN5M26+HiNC3VGFg46jmCOcNqc8dAjQ9wQ=; b=xmZhg8WfdQjZOrK1iyUBkhVnqdt9x+y3PCVBcCnH6ialkkMG2nZ2uIm+NA1C5PZ5v6 73vHBdv0SiwXT2T7QehAjTOhOldeS+fR5WkyvcmiCX158uWOih9jTy+hIA8qLypT4uF7 fErmDffVKJlAZthDmCgIF+s8hG+BufvkL7mtCNpaVU1BBQJo15ye1J/HB7yXO4HOWKrA RUvEOkvh6suG28h9CC2fhSZ7KlldZHrt29h4QpYs+gtO64c96KU1IrGRNevR7+oglCf4 veNeC9IoO6048nAameysNia75FgIuDiW/4m7O7BGIbgbHg/woWDqhupTXWrouT2J+6R/ +K2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=erJV2Pn4; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz31-20020a1709077d9f00b00730aa17d032si747586ejc.337.2022.08.10.15.31.01; Wed, 10 Aug 2022 15:31:55 -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=@gmail.com header.s=20210112 header.b=erJV2Pn4; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230118AbiHJW0n (ORCPT + 99 others); Wed, 10 Aug 2022 18:26:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbiHJW0m (ORCPT ); Wed, 10 Aug 2022 18:26:42 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5BB68D3E5 for ; Wed, 10 Aug 2022 15:26:41 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id b16so20872837edd.4 for ; Wed, 10 Aug 2022 15:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc; bh=Igs1I7eqEMN5M26+HiNC3VGFg46jmCOcNqc8dAjQ9wQ=; b=erJV2Pn4lUxZeCKjye4tdiaEU7zdvbVXpZ/l/Yoc7vTZ/TXFOboNBm28d5w0JIu6Y6 71oNe4DjMaH4gTE0VMtSg8CF3FaGjqdDTxCQADNl2Al5PvrSIMJIEWMfXq80yld/jz4r naJlAHUNqy3ky82hpDnromplpti8+B5cVYkZRCUOYbkv0j4u3EJtOOglPbtbJaEpMtpL RYztMCHIu21iz3eNYRqkNiP6D8H5vUrs0ZqKMCN663wN0reYykZcQeI0jc7YslotyTyf Uv8oGRa3B94RW5fJgR9+BxCTIGZ1FTuepnxj5eveObS3Kg95T+3u8DkOZOrSemqP6Oft G7Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=Igs1I7eqEMN5M26+HiNC3VGFg46jmCOcNqc8dAjQ9wQ=; b=bR88ZVpHID3QfXf0Uq026cuofHrpGl2//NsOWfe3pQbREQVQj6YA3dqvhdam6ZDYqH JROXmX5pSbILA/n8svsD4Lqwdu+4+anmQKN7DSq/MzLL5d0x2s7zGKl1GXEVdOsB1M6+ 5hOTSb7yixewZ8vEEBCIpvqjEeseacwlkaBwI6mqqY72KCOTqceyMHXdbIC5rI7ISLWv cHAjhmfoJS7AA5xODRJ+gW6td9ixcsMZb5+zsumW0QUGC9gKEXbydZyakfzuHqBolT3Y EJi40tk81L1bhP6qhEgSlnsyknKyhKH4d/+OF8U0RN39MvqiviWi1C6niYgmjeThn66M MdFQ== X-Gm-Message-State: ACgBeo3SuNNJLNNJcB60oddzUpcpLb7O/lStK6tr5rgX7rsT88vQX3eJ syDOjKpJUJBQlSowsL1Jund6TdQLSjYSeB1cVD0= X-Received: by 2002:a05:6402:438d:b0:43d:b383:660f with SMTP id o13-20020a056402438d00b0043db383660fmr28517020edc.283.1660170400249; Wed, 10 Aug 2022 15:26:40 -0700 (PDT) MIME-Version: 1.0 References: <20220807205740.777363-1-hdegoede@redhat.com> In-Reply-To: From: Luiz Augusto von Dentz Date: Wed, 10 Aug 2022 15:26:28 -0700 Message-ID: Subject: Re: [PATCH] Bluetooth: hci_event: Fix vendor (unknown) opcode status handling To: Hans de Goede Cc: Marcel Holtmann , Johan Hedberg , "linux-bluetooth@vger.kernel.org" , Luiz Augusto von Dentz Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 Hi Hans, On Mon, Aug 8, 2022 at 12:58 PM Luiz Augusto von Dentz wrote: > > Hi Hans, > > On Sun, Aug 7, 2022 at 1:57 PM Hans de Goede wrote: > > > > Commit c8992cffbe74 ("Bluetooth: hci_event: Use of a function table to > > handle Command Complete") was (presumably) meant to only refactor thing= s > > without any functional changes. > > > > But it does have one undesirable side-effect, before *status would alwa= ys > > 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 handl= ers. > > 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 baudr= aute > > 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 =3D 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 > > --- > > net/bluetooth/hci_event.c | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > > index af17dfb20e01..fda31d558ded 100644 > > --- a/net/bluetooth/hci_event.c > > +++ b/net/bluetooth/hci_event.c > > @@ -3996,6 +3996,13 @@ static void hci_cmd_complete_evt(struct hci_dev = *hdev, void *data, > > break; > > } > > } > > + if (i =3D=3D ARRAY_SIZE(hci_cc_table)) { > > + /* Unknown opcode, assume byte 0 contains the status, s= o > > + * that e.g. __hci_cmd_sync() properly returns errors > > + * for vendor specific commands send by HCI drivers. > > + */ > > + *status =3D skb->data[0]; > > + } > > The format of return parameters in command is not defined by the spec: > > BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E > page 2189: > > Return_Parameters: > Size: Depends on command > > This is the return parameter(s) for the command specified in the > Command_Opcode event parameter. See each command=E2=80=99s definition for > the list of return parameters associated with that command. > > So assuming the status is the first by is not quite right, although > for the standard ones that seems to be valid, I think the best way to > resolve this would have been to check if it a vendor command and then > have the driver handle it or perhaps have some means for the driver to > register it vendor_cc_table, we can perhaps have this as a workaround > for now and only really change how we parse the cc for vendor commands > if a vendor decide not to have a status as first parameter but Id > probably leave a comment that quoting the spec that reminds us this > code may need changing. Are you still planning to send updates for this, I consider this quite urgent given that it can break support with some vendors. > > handle_cmd_cnt_and_timer(hdev, ev->ncmd); > > > > -- > > 2.37.1 > > > > > -- > Luiz Augusto von Dentz --=20 Luiz Augusto von Dentz