Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp5148248rwb; Mon, 8 Aug 2022 13:06:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR51/OgRJR2AdhSqyoD2eulVxhshqk4baLEhedKHbhRIJtfpqn/3wJfxANiLiosbBG/Svi3c X-Received: by 2002:a17:906:8a70:b0:730:9c9e:edb2 with SMTP id hy16-20020a1709068a7000b007309c9eedb2mr14728634ejc.41.1659989168143; Mon, 08 Aug 2022 13:06:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659989168; cv=none; d=google.com; s=arc-20160816; b=P2nyhcch3KTN8QrmmCRgX5g0UkGR5WavbdIf5nYgk+TB1l4/hQzwSNUlrfd8NAkFEA s0H7NqzE9E0TSxXnTZhmb3GG/DtmXDVJA99eUA/kAzJipaul1eoGkeoDdxKfMce3gup4 s6zHnIy6L4XzQUiS7wVWGc17xggWBFwZRBc/kkZppweQN0TGD4wugL6MzJrkCrhgqsMn MSzqS9fcRYQcSdlQKesl+YrgNanLbQxpwTmUchBy8cgxgAMm7bFwydrsO2zcHO2XdhdU a1Pxok14iQ+cLWpeIwQI5l8Yz5lbiNUA8p3gCEil4FIlqjGlq/XsWxx5qf5sBUFf26Ak MG7w== 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=jYFh67Z/iJIySYzxW+dvqCfobkF6ZVpVJKcKqS5//xE=; b=Evdgq2qLzOQEhYaPVWDzp4fJtEq2O4kSEVs+Gv79rAkn+wSNgVlDpmsXAJhDK0iZXo vmyijjS+c+nk7NFag48wuaFNJWrc/tsisLGUFIpbfKP9G3bM3kPxkXMl7AMl+xLn09UT lr3SM8/xc5Gp8NuX/vwJpuHHVd8YilgB2Ou/oF6Yz6GxgEsT+WK8+XVacE7T4WQtFFgA gHTwooDwfeDb+s6mbQS0AajcvKvs8bdI+tI7Tuz9lJEI65G/C1xCtQqV2fCGDC00cX7I jiytLNbuoTiQjfbbLhLzTcaQMUtA21IE4crUTp3MfsZeDCMhDkeND0E8bg1gYu7JwAYD JeRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=f2n8v0zE; 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 p2-20020a50cd82000000b0043de558914asi7194475edi.487.2022.08.08.13.05.23; Mon, 08 Aug 2022 13:06:08 -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=f2n8v0zE; 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 S238096AbiHHT6e (ORCPT + 99 others); Mon, 8 Aug 2022 15:58:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236856AbiHHT6c (ORCPT ); Mon, 8 Aug 2022 15:58:32 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19A97A196 for ; Mon, 8 Aug 2022 12:58:31 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id j8so18485686ejx.9 for ; Mon, 08 Aug 2022 12:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=jYFh67Z/iJIySYzxW+dvqCfobkF6ZVpVJKcKqS5//xE=; b=f2n8v0zE9INU4TAz02rEJuWKBTOe47H6t/YRS+hKpCYt7/9CYtpPT/z9TmVREcQn7q bfGlYanlc2O4ZzrWMkSZeio4tr+RiWiNXeEgv56GRjjQtiEq7oLZ2zO1puKgPwsE95aM 9y7iAtlxKTCYkD3fpl4LNcmm76HdCfPCesQfaUgP4DADdPc1WPhK2Jis7rmvtO08o93h m5woG27hRmtfTOKJBGwc1TFPNwNE1BAV4r5nR5/CstT5E4dLxulcSaAPc+AUHToC4F6B hQ9b1CwTpXYQ60mG+f5Oyl2XQoabwjvD7o5uWdj+/AS8cici678oTmz6Cugq1hCwW5Wu DIQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=jYFh67Z/iJIySYzxW+dvqCfobkF6ZVpVJKcKqS5//xE=; b=0ZtA5Qa9xOO84ThghDGX2AFitpv6e5HBhbB4zhTJKLrTIBcpCuIlZScjOn6ZJTfOlh RJgPS3Zeo5ND3ft8GVvuL27Fh2zTTh8JqqY/7tq2L+FkRwi8RSGpQR+dX8JfsxpUgHqx rGTqrMSCXgNKleCBnhkL4njVZGV0Re+xInhcJFPor1JjlB+PCkq0cEC04cirabOLBDMf rj4XacuQyoukbA1v/FN+b/iKmallDkDfvECXQ2e96aVFWjf1qMjlJN2U+f47oEXFidwm 2JZTKtH48ttNyQ1mERkHio7QagOthqg0oZYd07p9+8rL6wAA2GtvX2X1gw7h0nTw2KJn BIng== X-Gm-Message-State: ACgBeo0sx+eCn7nKsYXxpdz3TC45/60c6D1rr+c86L9rDRK8M4G8wkBY UnJKDPjY5oQGUdoZt3+cwuGNN85fcKEG3KGZLFUVv30q/200IA== X-Received: by 2002:a17:907:2707:b0:730:af0b:3572 with SMTP id w7-20020a170907270700b00730af0b3572mr14478722ejk.411.1659988709585; Mon, 08 Aug 2022 12:58:29 -0700 (PDT) MIME-Version: 1.0 References: <20220807205740.777363-1-hdegoede@redhat.com> In-Reply-To: <20220807205740.777363-1-hdegoede@redhat.com> From: Luiz Augusto von Dentz Date: Mon, 8 Aug 2022 12:58:18 -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 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 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 handler= s. > 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 baudrau= te > 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 ha= ndle 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 *h= dev, void *data, > break; > } > } > + if (i =3D=3D 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. > + */ > + *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. > handle_cmd_cnt_and_timer(hdev, ev->ncmd); > > -- > 2.37.1 > --=20 Luiz Augusto von Dentz