From patchwork Mon Dec 19 21:37:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13077178 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E574C4332F for ; Mon, 19 Dec 2022 21:37:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232681AbiLSVhN (ORCPT ); Mon, 19 Dec 2022 16:37:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231693AbiLSVhH (ORCPT ); Mon, 19 Dec 2022 16:37:07 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 060CF13E23 for ; Mon, 19 Dec 2022 13:37:06 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id b13-20020a17090a5a0d00b0021906102d05so10146401pjd.5 for ; Mon, 19 Dec 2022 13:37:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=cr6/l6xNH/9Pi+33Q0P1XjTiBGSRTzK0/VL1DLYjTIE=; b=FYQJMyu47ZcfDAdWhgH3aLHAlOIJYdAu6bMyPCeblz/lMnTjtCx5vuxcV3KLHN8WEh 8jgwNBzbpQcs8Wq/9lJC52V9p3IR89Ul1of2nLTnOg9LIy+F5JcsqgmBIpGl8+uJVvsE azhgOXgeDhaNTwr7dLQHFC2oJxZJbxs1oMbANzsgIHxfVk/3dwHCvJ2TTUE91sby++UE jSA2juWIcosK2PakDCHkKhiblQec2hJCwYGCt1kvCRwyX2VmdT7w/kZy6/sXEcOxmGzJ gdTUF9DcIGbOgl6PHbaUdiHd751ROXynEBvyBpYcE4NyEhuEmpQl9b5t8/DzBJpXdJJN kbnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cr6/l6xNH/9Pi+33Q0P1XjTiBGSRTzK0/VL1DLYjTIE=; b=A9BUbYe4fKcIqqJv7MIUiytttd0uKJKLBnAYKzKm952ZILonyC2J5EOfQwNzglvRL1 +52ugHpOVpVVl8NqdkAYg5lBzAClDAIIY5QqG/v2rAZqC1KDbj/IeqZ87rnCzXtAyUbM oZOMyndWMx+9O7IngFlZ3vBui4R7u+ddExNLvOy/q/DSjc1MHH68YtrEtTOheeYR7++0 NsBFFy7/t+QH29LugdfiyWp5chb3N3hWY3WZDZaLZ3krCgSUeLgQnZVi7IgQDl2HW0vM e6KUhUrj9SjAblbkcnp3kRed9osfda2ygaBxRL2dpMEvHhDGvFNTznkffRLZiV4C7D1O oOTQ== X-Gm-Message-State: ANoB5plL5xPxldAUAX95g1R4ZL6DJ+2LRdCbMSt5cb6SwYWex4+vY/0M CxceQuh77yu9kECtlHQZkUr1dJuaCqt7sg== X-Google-Smtp-Source: AA0mqf6crRHzTBz9W8EjrrlChKzVm32Exzr99cg2fucJlY9VbHjpYDEMK9jncqDUGPpHb9qjSn6uYQ== X-Received: by 2002:a17:903:2345:b0:189:ba1f:b178 with SMTP id c5-20020a170903234500b00189ba1fb178mr64139773plh.9.1671485824891; Mon, 19 Dec 2022 13:37:04 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id ij24-20020a170902ab5800b00177efb56475sm7668116plb.85.2022.12.19.13.37.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 13:37:04 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [RESEND 1/2] Bluetooth: MGMT: Fix Set PHY Configuration command Date: Mon, 19 Dec 2022 13:37:01 -0800 Message-Id: <20221219213702.3659417-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz The command shall accept any subset that is considered configurable but instead it was only accepting the exact match causing errors such as: [mgmt]# phy Supported phys: BR1M1SLOT BR1M3SLOT BR1M5SLOT EDR2M1SLOT EDR2M3SLOT EDR2M5SLOT EDR3M1SLOT EDR3M3SLOT EDR3M5SLOT LE1MTX LE1MRX LE2MTX LE2MRX LECODEDTX LECODEDRX Configurable phys: BR1M3SLOT BR1M5SLOT EDR2M1SLOT EDR2M3SLOT EDR2M5SLOT EDR3M1SLOT EDR3M3SLOT EDR3M5SLOT LE2MTX LE2MRX LECODEDTX LECODEDRX Selected phys: BR1M1SLOT BR1M3SLOT BR1M5SLOT EDR2M1SLOT EDR2M3SLOT EDR2M5SLOT EDR3M1SLOT EDR3M3SLOT EDR3M5SLOT LE1MTX LE1MRX [mgmt]# phy BR1M3SLOT BR1M5SLOT EDR2M1SLOT EDR2M3SLOT EDR2M5SLOT EDR3M1SLOT EDR3M3SLOT EDR3M5SLOT LE2MTX LE2MRX Could not set PHY Configuration with status 0x0d (Invalid Parameters) Fixes: 0314f2867fa0 ("Bluetooth: Implement Set PHY Confguration command") Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/mgmt.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 0dd30a3beb77..dad6fd9abe95 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -4022,8 +4022,8 @@ static int set_default_phy_sync(struct hci_dev *hdev, void *data) if (!(selected_phys & MGMT_PHY_LE_RX_MASK)) cp_phy.all_phys |= 0x02; - if (selected_phys & MGMT_PHY_LE_1M_TX) - cp_phy.tx_phys |= HCI_LE_SET_PHY_1M; + /* 1M PHY shall always be supported */ + cp_phy.tx_phys |= HCI_LE_SET_PHY_1M; if (selected_phys & MGMT_PHY_LE_2M_TX) cp_phy.tx_phys |= HCI_LE_SET_PHY_2M; @@ -4031,8 +4031,8 @@ static int set_default_phy_sync(struct hci_dev *hdev, void *data) if (selected_phys & MGMT_PHY_LE_CODED_TX) cp_phy.tx_phys |= HCI_LE_SET_PHY_CODED; - if (selected_phys & MGMT_PHY_LE_1M_RX) - cp_phy.rx_phys |= HCI_LE_SET_PHY_1M; + /* 1M PHY shall always be supported */ + cp_phy.rx_phys |= HCI_LE_SET_PHY_1M; if (selected_phys & MGMT_PHY_LE_2M_RX) cp_phy.rx_phys |= HCI_LE_SET_PHY_2M; @@ -4051,14 +4051,13 @@ static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev, { struct mgmt_cp_set_phy_configuration *cp = data; struct mgmt_pending_cmd *cmd; - u32 selected_phys, configurable_phys, supported_phys, unconfigure_phys; + u32 selected_phys, supported_phys; u16 pkt_type = (HCI_DH1 | HCI_DM1); bool changed = false; int err; bt_dev_dbg(hdev, "sock %p", sk); - configurable_phys = get_configurable_phys(hdev); supported_phys = get_supported_phys(hdev); selected_phys = __le32_to_cpu(cp->selected_phys); @@ -4067,13 +4066,6 @@ static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev, MGMT_OP_SET_PHY_CONFIGURATION, MGMT_STATUS_INVALID_PARAMS); - unconfigure_phys = supported_phys & ~configurable_phys; - - if ((selected_phys & unconfigure_phys) != unconfigure_phys) - return mgmt_cmd_status(sk, hdev->id, - MGMT_OP_SET_PHY_CONFIGURATION, - MGMT_STATUS_INVALID_PARAMS); - if (selected_phys == get_selected_phys(hdev)) return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_PHY_CONFIGURATION, From patchwork Mon Dec 19 21:37:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13077179 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 052CEC4332F for ; Mon, 19 Dec 2022 21:37:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232850AbiLSVhP (ORCPT ); Mon, 19 Dec 2022 16:37:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232714AbiLSVhL (ORCPT ); Mon, 19 Dec 2022 16:37:11 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A7F5F580 for ; Mon, 19 Dec 2022 13:37:07 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id t11-20020a17090a024b00b0021932afece4so14467089pje.5 for ; Mon, 19 Dec 2022 13:37:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=aZWkJDxWk2tuT267UaOBtSBOXHIMzexEiUVFKl+weHk=; b=HfPyBNRQBevlyL85oKH3nQt9+Ell1AcdIn7X4IqE4RG6GuabEhlVRcCup1ytjVtV+d 3GIOVpWqsdblohX/5hBQCQ2sjFcVQd/HNZDa4cLSuOgjLgxRiTmdQucW2Zn8sH5xqjPA 5+kGSWRxiaYi5Vg3k3wXLuTf9cqtpx7haFogQMiT3UPXfbgILdG4raU6ESAyl4L6WcG4 UdQNY1jEvozrgvIDhKD4HJ7i7y6+wLWs11KB7SKfDqNQ2GYrm4yOWcDbgr0XQgRD9RAl flcoI1eqErmXoOX+s39htcmIGsnu1F0lyJvdjxPSYf21OWQQT4vXSmd3/T4w2tIZw0a2 7BZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aZWkJDxWk2tuT267UaOBtSBOXHIMzexEiUVFKl+weHk=; b=u+RjaJ5O/J87vOWwrB1Ml7903vv8dBpT9wV7l3wZgH9Nc65wsmnBkIQ77gmonv9JDz fbK3ujrC8znQKr/X7jm7u6VLUXm2DwgJ0+KH+FXfYASwKlQTsSsN8Hyt2zT8xWAFKm2o bWpFEbsjMenNuDjLMBfiNOfAVwkAk0ORatgvTBSOFA2uQwuUyrPnkM/gBEgVmKZ6iRuK n4NA0WkxbVKBaFnassapn8vr0z6zTar980Bhcp51mELWfqQjltO+8Jk2xkpqDzed45KA E2D9pMA6gHFi2KL2aKBZfb2hHuvq0UF+t5KXPNwtEsg4miHU5swu9VUuQuxTlIHtVV94 M24Q== X-Gm-Message-State: ANoB5pm/hQx2k7u2UURItDkU2qv6Xgg69V9Std16lnnemKYwJTtYuuKm +ZP2NobWmoaVPnmG6dv6i6S66dXZEHpoOA== X-Google-Smtp-Source: AA0mqf4L3EysxUolqMMmxRwF8I1ULvOc92f+7wnitXYusTZX2nOLGCjlRhp075dKk+OHXMoh4w0Lfw== X-Received: by 2002:a17:903:26c1:b0:189:5ae5:5b41 with SMTP id jg1-20020a17090326c100b001895ae55b41mr41686844plb.53.1671485826265; Mon, 19 Dec 2022 13:37:06 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id ij24-20020a170902ab5800b00177efb56475sm7668116plb.85.2022.12.19.13.37.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 13:37:05 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [RESEND 2/2] Bluetooth: Enable all supported LE PHY by default Date: Mon, 19 Dec 2022 13:37:02 -0800 Message-Id: <20221219213702.3659417-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221219213702.3659417-1-luiz.dentz@gmail.com> References: <20221219213702.3659417-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This enables 2M and Coded PHY by default if they are marked as supported in the LE features bits. Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci_core.h | 4 ++++ net/bluetooth/hci_sync.c | 28 ++++++++++++++++++++++++---- net/bluetooth/mgmt.c | 4 ++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 7254edfba4c9..675ce50a0247 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1666,9 +1666,13 @@ void hci_conn_del_sysfs(struct hci_conn *conn); #define scan_1m(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_1M) || \ ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_1M)) +#define le_2m_capable(dev) (((dev)->le_features[1] & HCI_LE_PHY_2M)) + #define scan_2m(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_2M) || \ ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_2M)) +#define le_coded_capable(dev) (((dev)->le_features[1] & HCI_LE_PHY_CODED)) + #define scan_coded(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \ ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED)) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 9e2d7e4b850c..5220bfd75b00 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -4370,18 +4370,38 @@ static int hci_le_set_write_def_data_len_sync(struct hci_dev *hdev) sizeof(cp), &cp, HCI_CMD_TIMEOUT); } -/* Set Default PHY parameters if command is supported */ +/* Set Default PHY parameters if command is supported, enables all supported + * PHYs according to the LE Features bits. + */ static int hci_le_set_default_phy_sync(struct hci_dev *hdev) { struct hci_cp_le_set_default_phy cp; - if (!(hdev->commands[35] & 0x20)) + if (!(hdev->commands[35] & 0x20)) { + /* If the command is not supported it means only 1M PHY is + * supported. + */ + hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; + hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; return 0; + } memset(&cp, 0, sizeof(cp)); cp.all_phys = 0x00; - cp.tx_phys = hdev->le_tx_def_phys; - cp.rx_phys = hdev->le_rx_def_phys; + cp.tx_phys = HCI_LE_SET_PHY_1M; + cp.rx_phys = HCI_LE_SET_PHY_1M; + + /* Enables 2M PHY if supported */ + if (le_2m_capable(hdev)) { + cp.tx_phys |= HCI_LE_SET_PHY_2M; + cp.rx_phys |= HCI_LE_SET_PHY_2M; + } + + /* Enables Coded PHY if supported */ + if (le_coded_capable(hdev)) { + cp.tx_phys |= HCI_LE_SET_PHY_CODED; + cp.rx_phys |= HCI_LE_SET_PHY_CODED; + } return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_DEFAULT_PHY, sizeof(cp), &cp, HCI_CMD_TIMEOUT); diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index dad6fd9abe95..9e86bd979a53 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -8380,10 +8380,10 @@ static u32 get_supported_adv_flags(struct hci_dev *hdev) flags |= MGMT_ADV_FLAG_HW_OFFLOAD; flags |= MGMT_ADV_FLAG_CAN_SET_TX_POWER; - if (hdev->le_features[1] & HCI_LE_PHY_2M) + if (le_2m_capable(hdev)) flags |= MGMT_ADV_FLAG_SEC_2M; - if (hdev->le_features[1] & HCI_LE_PHY_CODED) + if (le_coded_capable(hdev)) flags |= MGMT_ADV_FLAG_SEC_CODED; }