Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1073901rwr; Thu, 27 Apr 2023 11:58:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6/GSbyBXSvN3Ih3sCJx8OY25fuyH5F3e+ERjRWkzlvqsQHMID01GLoKysQT4oxmNus8A3Y X-Received: by 2002:a17:903:120f:b0:1a6:5118:cb95 with SMTP id l15-20020a170903120f00b001a65118cb95mr2898045plh.23.1682621916603; Thu, 27 Apr 2023 11:58:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682621916; cv=none; d=google.com; s=arc-20160816; b=URjlGD/vw5U+wYmUdVtu9QIk/DWHU4HwM6r7poW9rzBZASW3NSS5xJPqneWPL2cg6s OMpJc+m9fgX/sPuCmScVpinDR+8JlEFkiDHMS0WwWEi8qVedaSGxggrbKWzocbdfJycj ezW8o3zq6JYywx2io/wRrt1Sato1sG21o/UeF3yXTyw5vWawlHPLPIcQ1wJW+7kFH52i uFk6Jyj25ND1qAf10FbIPWeeIzg+0DnHBfuPGD1J3F7fLVOlEjY2kQ5ZHHhdg7Z8auPO ggBxEdDUZWq/fziOXeRLrlnwIVVXCibfXYSrJJezkjsMtX7tYaWU/QcjFwnpU0ezuwOw 99Gw== 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=TSw1IlHabKdeoJWFqhha6ktdPaX7I8X8moKzfrrA+xs=; b=UWrPHSgmaxHnzeD9MrEXiR6+2KjB4K3zchkB/K3UCPaSgIyLO/QliUP/zjKUQ6ets4 DFXItZWHDGk0As3mrJeDzDjlH6hTIUYF84o/PZXBR2no/5IWcZOM1LsIhZ4pO8DmpnjT HocFi7lf8EY9CutsqxMLkYSR9ypbF5GUCgE46JARYzP/gTduOHoZgfeZT6OdvCN0HRrF hKsGcvRYAuOWrhmpyUs7rxNdg6xxNr1fzV0YtxhLkhC3jEyFRztTuFsmOjlRNG2S+H1S jGmqAZhnLtRoJAmyug46dV5Y5MooItZpJMbFGIyypF5nMxHl0dPzMqJBRkwoHRwp6vG6 HKtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=c5VdzcPt; 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 ks7-20020a170903084700b001a1e2b6b9d7si18709629plb.430.2023.04.27.11.58.10; Thu, 27 Apr 2023 11:58:36 -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=20221208 header.b=c5VdzcPt; 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 S243639AbjD0SuJ (ORCPT + 99 others); Thu, 27 Apr 2023 14:50:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233136AbjD0SuI (ORCPT ); Thu, 27 Apr 2023 14:50:08 -0400 Received: from mail-oo1-xc32.google.com (mail-oo1-xc32.google.com [IPv6:2607:f8b0:4864:20::c32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6711E359D for ; Thu, 27 Apr 2023 11:50:07 -0700 (PDT) Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-549f0b45ac6so1177947eaf.0 for ; Thu, 27 Apr 2023 11:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682621406; x=1685213406; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TSw1IlHabKdeoJWFqhha6ktdPaX7I8X8moKzfrrA+xs=; b=c5VdzcPthUwYt+fAt1IPr3kLAhLRh0w+qstLZEj8WYb3uGognGMUbKZJcJEN83rBrU 9hD046zwbrCiaOfD1uTLKwJDo1lFoSaiBiNWwuRuQKyvCfZy5s42WTg7XiDWyGXOSReW a9732IBAlF6O1sT9IdCv1z3pwsPDR23SFeox4kc2hdvejZwFLzFQ05zJ63YjgYMYRPxB 4C0leKMWCzdn9wnfYPJWY5uuynAGH+W8SwZHElwsF9WzL3eqP/Y07NsbjYR35wgMguu6 IleTVey38i11ADRQi/9hbvnFKkrXd0IL0ovdSq/58MXpc5sLLrLq2RykDGZSnK50qlKJ rDRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682621406; x=1685213406; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TSw1IlHabKdeoJWFqhha6ktdPaX7I8X8moKzfrrA+xs=; b=Enti7niP/Jp6qEiZcSXunW1SzgZwIR/O8Emd1zhnZ8s0kXU+KuiODjXXTL/P37uBss /MKHrj9j05c0+nTzC44/H5pDMaw7me3AN6QoUGGfH7Lgo733uT06+TuL7e/kmonImAtc Ient0FDq/EI0YD/bQx+7VTgjorXJB3zr8ZAqXh2/UaTnj8ETlmjBWMX8kzQU4OYibFFh cjLOyy0SvxOSuLJQYcRE75Q9yr1HCp0ut7kcnAHs0vI1JloO4H09v6enrT35/l3gTrbu dqfwcebFrv2+xU9++Ng0NVkEh/nMemmq2+RZZytr02GDKlmmk06TpsuRFAK/TQAc+x5p I1Ng== X-Gm-Message-State: AC+VfDwtVOTZH9GMYaNYcWQC4vwGmWidtjQfIJ1o7gKyJWhke/28e4qT KO1CBUs0F53ybGg041vnYto7N/CgrER+/zIcnIX4JEWhIw+fpwMC X-Received: by 2002:a05:6808:60f:b0:38e:8d92:5884 with SMTP id y15-20020a056808060f00b0038e8d925884mr1092207oih.12.1682621406035; Thu, 27 Apr 2023 11:50:06 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Raul Cheleguini Date: Thu, 27 Apr 2023 15:49:29 -0300 Message-ID: Subject: Re: unexpected SMP command errors with controller ATS2851 To: linux-bluetooth@vger.kernel.org Cc: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com 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 On Fri, Mar 24, 2023 at 12:17=E2=80=AFAM Raul Cheleguini wrote: > > Hi everyone, > > I'm trying to understand and narrow down a pairing problem with this > controller that I'm trying to make it work in Linux. > > When pairing, the negotiation does not complete and the system logs > the following messages: > > Bluetooth: hci0: unexpected SMP command 0x08 from dd:5e:b9:fe:49:3f > Bluetooth: hci0: unexpected SMP command 0x09 from dd:5e:b9:fe:49:3f > Bluetooth: hci0: Opcode 0x200d failed: -110 > Bluetooth: hci0: request failed to create LE connection: err -110 > > (dd:5e:b9:fe:49:3f is my bluetooth mouse) > > After some debug I found the condition that refuses the SMP commands and > drops them: > > net/bluetooth/smp.c in smp_sig_channel() > > if (smp && !test_and_clear_bit(code, &smp->allow_cmd)) > goto drop; > > The interesting part is that if I disable this condition with comments, > the pairing process manages to complete and my bluetooth mouse starts to = work > (even with some errors in logs): > > Bluetooth: hci0: Opcode 0x200d failed: -110 > Bluetooth: hci0: request failed to create LE connection: err -110 > hid: raw HID events driver (C) Jiri Kosina > input: Logi M650 L Mouse as /devices/virtual/misc/uhid/0005:046D:B02A.000= 1/ > input/input6 > hid-generic 0005:046D:B02A.0001: input,hidraw0: BLUETOOTH HID v0.09 Mouse > [Logi M650 L] on f4:4e:fc:c0:de:5e > Bluetooth: hci0: Opcode 0x200d failed: -110 > Bluetooth: hci0: request failed to create LE connection: err -110 > > Logs from bluetoothd receiving the mouse data events: > > bluetoothd[576]: src/shared/att.c:can_read_data() (chan 0x55f8ad8db380) > ATT PDU received: 0x1b > bluetoothd[576]: src/shared/att.c:can_read_data() (chan 0x55f8ad8db380) > ATT PDU received: 0x1b > bluetoothd[576]: src/shared/att.c:can_read_data() (chan 0x55f8ad8db380) > ATT PDU received: 0x1b > > I kindly ask guidance on what could be done in these cases or any hints > how to further debug this issue. > > For context, the controller works in other systems using generic drivers. > > Regards, > Raul. For the benefit of any novice who may face similar situation in future: The error "unexpected SMP command 0x08" indicates that command 0x08 (SMP_CMD_IDENT_INFO) arrives before it has been allowed. That is part smp implementation, it allows commands and responds to them in the expected context, otherwise it drops them. In this particular situation, we enter a condition in hci_encrypt_change_ev= t() [1] that results in an unrelated HCI command being sent during the time we should be preparing to receive command 0x08. The command 0x08 arrives befor= e it has been allowed and this confusion eventually leads to a disconnect eve= nt. According to my raw notes, 0x08 is allowed in smp_allow_key_dist(), as a result of a callback chain for this type of connection/adapter: hci_encrypt_cfm > security_cfm_cb > l2cap_security_cfm > smp_resume_cb > smp_distribute_keys > smp_allow_key_di= st Regards, Raul. [1] https://elixir.bootlin.com/linux/v6.3/source/net/bluetooth/hci_event.c#L367= 0