From patchwork Thu Jul 22 05:38:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Garg X-Patchwork-Id: 12393137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9633EC63793 for ; Thu, 22 Jul 2021 05:59:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D74B61279 for ; Thu, 22 Jul 2021 05:59:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230261AbhGVFTT (ORCPT ); Thu, 22 Jul 2021 01:19:19 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:44113 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230286AbhGVFTS (ORCPT ); Thu, 22 Jul 2021 01:19:18 -0400 Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20210722055952epoutp0441bd2f7540c2b032e7012684a2074b80~UB3uglv-10482404824epoutp04c for ; Thu, 22 Jul 2021 05:59:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20210722055952epoutp0441bd2f7540c2b032e7012684a2074b80~UB3uglv-10482404824epoutp04c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1626933592; bh=gLi5izO2emW1/Xuquhpo4cj7f9PNlRDquW1Z4C/UgsY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TEdaBFLaotVuNE+8ocJdI90Blv6qty5EBJ9mzRExaJ2+zhUKIbB96/whqHcuXGEz0 +IJteh8Rs0FkT4NTXYRbCn4PWxCeGP4JhTRJfXSVRMeN7k754FSX9iavpGC5eTqil1 SCj+mkwo3jHsqJfR96UI6Vh/rO4Yk7HfJNHvC+2o= Received: from epsmges5p2new.samsung.com (unknown [182.195.42.74]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20210722055952epcas5p263d136220bf91e26f153cb81471528f8~UB3uFaSU-0624506245epcas5p2o; Thu, 22 Jul 2021 05:59:52 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id D9.7A.09595.85909F06; Thu, 22 Jul 2021 14:59:52 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20210722053859epcas5p4b9441d43196ee1111b33b7c8d4827262~UBlfeAX5k2579925799epcas5p4F; Thu, 22 Jul 2021 05:38:59 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20210722053859epsmtrp2e2816c99467e7f80a3617885c652dd17~UBlfS4Uyn0680906809epsmtrp2p; Thu, 22 Jul 2021 05:38:59 +0000 (GMT) X-AuditID: b6c32a4a-eebff7000000257b-68-60f90958aa51 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 6E.C2.08394.37409F06; Thu, 22 Jul 2021 14:38:59 +0900 (KST) Received: from ayush.garg-20-10-15 (unknown [107.109.98.149]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20210722053858epsmtip25b95660dc4369213d87375de0496c47c~UBleXzwbA1183911839epsmtip2b; Thu, 22 Jul 2021 05:38:58 +0000 (GMT) From: Ayush Garg To: linux-bluetooth@vger.kernel.org Cc: anupam.r@samsung.com, nitin.j@samsung.com Subject: [PATCH 1/4] Bluetooth: Fix incorrect parsing of LE_PHY params Date: Thu, 22 Jul 2021 11:08:40 +0530 Message-Id: <20210722053843.6691-2-ayush.garg@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210722053843.6691-1-ayush.garg@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMIsWRmVeSWpSXmKPExsWy7bCmpm4E588Eg8XPOCzurLa2mHOtj9li 27p2Zgdmj74tqxg9Pm+SC2CK4rJJSc3JLEst0rdL4Mo4tqSPreC9YMWrx4vYGxiv8nUxcnBI CJhI9E1S7WLk4hAS2M0oseP0LCYI5xOjREffBCjnG6PE/s59zF2MnGAdG47tYoFI7GWUeLOs gxWu5cHKj2wgVWwCmhKvP35hArFFBJQlnu07DGYzC+hKnHm/DqxGWMBNYv/2dYwgNouAqsTu 9TvBNvAKWElMa5rJCLFNXmL1hgNgcU4Ba4k5jfPZQJZJCExnl7i28h4bRJGLxKFrE6FsYYlX x7ewQ9hSEp/f7YVqaAb6bvNGdginB+jUH91QHfYS55qesYKCgxno7PW79CHCshJTT62DuppP ovf3EyaIOK/EjnkwtorEhlWdcMs+HlsIDSMPiQ3rNrNDgqWPUWJi91G2CYxysxBWLGBkXMUo mVpQnJueWmxaYJSXWq5XnJhbXJqXrpecn7uJERzPWl47GB8++KB3iJGJg/EQowQHs5IIr0rR 1wQh3pTEyqrUovz4otKc1OJDjNIcLErivOzxQCmB9MSS1OzU1ILUIpgsEwenVAOTb9Dlo3GC pZnMWzX/LPmtOT8rls/odJrYhvltS4JFg9dF9Kjn8hsVep96FcNbP+fWoU/yxufbd3ls2Blv s9fH46H2wqC1PGGfTyVd2uZ11m3/dufrKw6HGpYc39ihWK20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u2TNBWudPZW3Ty/9Xam2/SLXjmn212bnuutHvFFiKc5INNRiLipOBAANeaEFhAIAAA== X-CMS-MailID: 20210722053859epcas5p4b9441d43196ee1111b33b7c8d4827262 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20210722053859epcas5p4b9441d43196ee1111b33b7c8d4827262 References: <20210722053843.6691-1-ayush.garg@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This change is fixing the parsing of PHY LE CODED which is represented with value 0x03 instead of 0x04 in LE PHY Update Complete event. > HCI Event: LE Meta Event (0x3e) plen 6 LE PHY Update Complete (0x0c) Status: Success (0x00) Handle: 0 TX PHY: LE Coded (0x03) RX PHY: LE Coded (0x03) Reviewed-by: Anupam Roy Signed-off-by: Ayush Garg --- include/net/bluetooth/hci.h | 4 ++++ net/bluetooth/hci_conn.c | 21 +++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index b80415011dcd..56542a09ec43 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -1681,6 +1681,10 @@ struct hci_cp_le_set_default_phy { #define HCI_LE_SET_PHY_2M 0x02 #define HCI_LE_SET_PHY_CODED 0x04 +#define HCI_LE_READ_PHY_1M 0x01 +#define HCI_LE_READ_PHY_2M 0x02 +#define HCI_LE_READ_PHY_CODED 0x03 + #define HCI_OP_LE_SET_EXT_SCAN_PARAMS 0x2041 struct hci_cp_le_set_ext_scan_params { __u8 own_addr_type; diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 2b5059a56cda..383efd969840 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1915,22 +1915,19 @@ u32 hci_conn_get_phy(struct hci_conn *conn) break; case LE_LINK: - if (conn->le_tx_phy & HCI_LE_SET_PHY_1M) - phys |= BT_PHY_LE_1M_TX; - - if (conn->le_rx_phy & HCI_LE_SET_PHY_1M) - phys |= BT_PHY_LE_1M_RX; - if (conn->le_tx_phy & HCI_LE_SET_PHY_2M) + if (conn->le_tx_phy == HCI_LE_READ_PHY_1M) + phys |= BT_PHY_LE_1M_TX; + else if (conn->le_tx_phy == HCI_LE_READ_PHY_2M) phys |= BT_PHY_LE_2M_TX; - - if (conn->le_rx_phy & HCI_LE_SET_PHY_2M) - phys |= BT_PHY_LE_2M_RX; - - if (conn->le_tx_phy & HCI_LE_SET_PHY_CODED) + else if (conn->le_tx_phy == HCI_LE_READ_PHY_CODED) phys |= BT_PHY_LE_CODED_TX; - if (conn->le_rx_phy & HCI_LE_SET_PHY_CODED) + if (conn->le_rx_phy == HCI_LE_READ_PHY_1M) + phys |= BT_PHY_LE_1M_RX; + else if (conn->le_rx_phy == HCI_LE_READ_PHY_2M) + phys |= BT_PHY_LE_2M_RX; + else if (conn->le_rx_phy == HCI_LE_READ_PHY_CODED) phys |= BT_PHY_LE_CODED_RX; break; From patchwork Thu Jul 22 05:38:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Garg X-Patchwork-Id: 12393139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A3BBC6377D for ; Thu, 22 Jul 2021 06:00:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5165B61244 for ; Thu, 22 Jul 2021 06:00:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230337AbhGVFTY (ORCPT ); Thu, 22 Jul 2021 01:19:24 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:40171 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230255AbhGVFTV (ORCPT ); Thu, 22 Jul 2021 01:19:21 -0400 Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20210722055956epoutp0382a6d08fe18b1745b5fb852b3c1756b2~UB3xk-DVt0618306183epoutp03j for ; Thu, 22 Jul 2021 05:59:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20210722055956epoutp0382a6d08fe18b1745b5fb852b3c1756b2~UB3xk-DVt0618306183epoutp03j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1626933596; bh=lPkysQYmSXHnQUX3l0i1LE71r9ldEKU/cKhT+tvmFus=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cuVMzmF5UFWBOWbweHQN7WjH15NtI02lofZjnYdRGN/XiLHX6L4L9ViAUEIIqymXy o1zIE3QtmJSp6r/LSMR6GbO4ZbvaJO+8YfDdi0x9twZKNGZ4RZaLXQ4c1rlHEpumio 2pddBijYQdFluqvaQHrUxX8LJXsLSVk5zjjuti5c= Received: from epsmges5p3new.samsung.com (unknown [182.195.42.75]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20210722055955epcas5p4887dc1e3b9aeeb168500d0274a7a0cb6~UB3xPTnYg2202722027epcas5p4f; Thu, 22 Jul 2021 05:59:55 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 41.EA.11627.B5909F06; Thu, 22 Jul 2021 14:59:55 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20210722053900epcas5p48430eb1335c3e566be02135e63749f33~UBlgeMHFp0983809838epcas5p4X; Thu, 22 Jul 2021 05:39:00 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20210722053900epsmtrp1e9874d8e255cf2b4dbba56cc6d88ff4e~UBlgXYMrz2559625596epsmtrp1Y; Thu, 22 Jul 2021 05:39:00 +0000 (GMT) X-AuditID: b6c32a4b-acdff70000022d6b-04-60f9095b8313 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 1F.C2.08394.47409F06; Thu, 22 Jul 2021 14:39:00 +0900 (KST) Received: from ayush.garg-20-10-15 (unknown [107.109.98.149]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20210722053859epsmtip27a258cd43b7952354943057821bc4e0e~UBlfaQ5_M0950409504epsmtip2T; Thu, 22 Jul 2021 05:38:59 +0000 (GMT) From: Ayush Garg To: linux-bluetooth@vger.kernel.org Cc: anupam.r@samsung.com, nitin.j@samsung.com Subject: [PATCH 2/4] Bluetooth: Implement BT_PHY setsocket option Date: Thu, 22 Jul 2021 11:08:41 +0530 Message-Id: <20210722053843.6691-3-ayush.garg@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210722053843.6691-1-ayush.garg@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrIIsWRmVeSWpSXmKPExsWy7bCmhm40588Eg5kX5C3urLa2mHOtj9li 27p2Zgdmj74tqxg9Pm+SC2CK4rJJSc3JLEst0rdL4Mo4MLeBvWC2dsW8nqssDYyTlbsYOTkk BEwkZjTtZe9i5OIQEtjNKLHr5RkmkISQwCdGiVe/fCAS3xgl5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W0RAWeLZvsNgNrOAvsTTC9cZQeYICzhK7FnjARJmEVCVuL/pNQuIzStgJbG2+SIz xHx5idUbDoDZnALWEnMa57OBtAoB1Sxq95jAyLeAkWEVo2RqQXFuem6xYYFhXmq5XnFibnFp Xrpecn7uJkZwoGhp7mDcvuqD3iFGJg7GQ4wSHMxKIrwqRV8ThHhTEiurUovy44tKc1KLDzFK c7AoifNe6DoZLySQnliSmp2aWpBaBJNl4uCUamBSirROVIu5vWXtnF/q2woO7ezViBL5/Hf2 BO2Qt9Lz/2mI6L/hW/BXXVpgIYPmjPlVP0OPm6kuFr3T6LzBy6T1b+d7V5+PHyxsC7emfNd9 3ZTKN6VTvNBAYk2anPzzB3Ze6eKWRwXuuBtP/bSN67Lpt31FDcXnfH9rTGQ7u60/XMN9hmaJ 0dWNXEb7J+0pyMveNmma2q6P67W23HnefvHlMf0X/Q+WVJTY1065ksQdlGPys9OoQz7j/0kF 53MLwhbZ8b7d+PfdoXPeKxa+afGbfWGi0tFj51a9VBVbd6n0sW1Rs3xi3rZTdWXaX+o3L8zY +9PiwnnXOSq52dvn13dLT699cCXzSqVP8uFDnPO5lViKMxINtZiLihMB1fGE3YMCAAA= X-CMS-MailID: 20210722053900epcas5p48430eb1335c3e566be02135e63749f33 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20210722053900epcas5p48430eb1335c3e566be02135e63749f33 References: <20210722053843.6691-1-ayush.garg@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds BT_PHY setsocket option which can be used to set the PHYs for the underline LE connection. < HCI Command: LE Set PHY (0x08|0x0032) plen 7 Handle: 0 All PHYs preference: 0x00 TX PHYs preference: 0x02 LE 2M RX PHYs preference: 0x02 LE 2M PHY options preference: Reserved (0x0000) > HCI Event: Command Status (0x0f) plen 4 LE Set PHY (0x08|0x0032) ncmd 1 Status: Success (0x00) > HCI Event: LE Meta Event (0x3e) plen 6 LE PHY Update Complete (0x0c) Status: Success (0x00) Handle: 0 TX PHY: LE 2M (0x02) RX PHY: LE 2M (0x02) Reviewed-by: Anupam Roy Signed-off-by: Ayush Garg --- include/net/bluetooth/bluetooth.h | 7 ++++ include/net/bluetooth/hci.h | 12 +++++++ include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_conn.c | 56 +++++++++++++++++++++++++++++++ net/bluetooth/l2cap_sock.c | 21 +++++++++++- 5 files changed, 96 insertions(+), 1 deletion(-) diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 9125effbf448..af53a98e4236 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -140,6 +140,13 @@ struct bt_voice { #define BT_PHY_LE_2M_RX 0x00001000 #define BT_PHY_LE_CODED_TX 0x00002000 #define BT_PHY_LE_CODED_RX 0x00004000 +#define BT_PHY_LE_CODED_S2 0x00008000 +#define BT_PHY_LE_CODED_S8 0x00010000 + +#define BT_PHY_LE_TX_MASK (BT_PHY_LE_1M_TX | BT_PHY_LE_2M_TX | \ + BT_PHY_LE_CODED_TX) +#define BT_PHY_LE_RX_MASK (BT_PHY_LE_1M_RX | BT_PHY_LE_2M_RX | \ + BT_PHY_LE_CODED_RX) #define BT_MODE 15 diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 56542a09ec43..06e10ccf2a1c 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -1677,10 +1677,22 @@ struct hci_cp_le_set_default_phy { __u8 rx_phys; } __packed; +#define HCI_OP_LE_SET_PHY 0x2032 +struct hci_cp_le_set_phy { + __le16 handle; + __u8 all_phys; + __u8 tx_phys; + __u8 rx_phys; + __le16 phy_opt; +} __packed; + #define HCI_LE_SET_PHY_1M 0x01 #define HCI_LE_SET_PHY_2M 0x02 #define HCI_LE_SET_PHY_CODED 0x04 +#define HCI_LE_PHY_CODED_S2 0x01 +#define HCI_LE_PHY_CODED_S8 0x02 + #define HCI_LE_READ_PHY_1M 0x01 #define HCI_LE_READ_PHY_2M 0x02 #define HCI_LE_READ_PHY_CODED 0x03 diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index a53e94459ecd..257467f9d28d 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1702,6 +1702,7 @@ struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, const void *param, u32 timeout); u32 hci_conn_get_phy(struct hci_conn *conn); +int hci_conn_set_phy(struct hci_conn *conn, u32 phys); /* ----- HCI Sockets ----- */ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb); diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 383efd969840..3b69c7cb9523 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1935,3 +1935,59 @@ u32 hci_conn_get_phy(struct hci_conn *conn) return phys; } + +int hci_conn_set_phy(struct hci_conn *conn, u32 phys) +{ + struct hci_cp_le_set_phy cp_phy; + u16 phy_opt = 0; + + if (conn->type != LE_LINK) + return -ENOTCONN; + + /* Check whether HCI_LE_Set_PHY command is supported or not */ + if (!(conn->hdev->commands[35] & 0x40)) + return -EOPNOTSUPP; + + hci_dev_lock(conn->hdev); + + memset(&cp_phy, 0, sizeof(cp_phy)); + cp_phy.handle = cpu_to_le16(conn->handle); + + if (!(phys & BT_PHY_LE_TX_MASK)) + cp_phy.all_phys |= 0x01; + + if (!(phys & BT_PHY_LE_RX_MASK)) + cp_phy.all_phys |= 0x02; + + if (phys & BT_PHY_LE_1M_TX) + cp_phy.tx_phys |= HCI_LE_SET_PHY_1M; + + if (phys & BT_PHY_LE_2M_TX) + cp_phy.tx_phys |= HCI_LE_SET_PHY_2M; + + if (phys & BT_PHY_LE_CODED_TX) + cp_phy.tx_phys |= HCI_LE_SET_PHY_CODED; + + if (phys & BT_PHY_LE_1M_RX) + cp_phy.rx_phys |= HCI_LE_SET_PHY_1M; + + if (phys & BT_PHY_LE_2M_RX) + cp_phy.rx_phys |= HCI_LE_SET_PHY_2M; + + if (phys & BT_PHY_LE_CODED_RX) + cp_phy.rx_phys |= HCI_LE_SET_PHY_CODED; + + if (phys & BT_PHY_LE_CODED_S2) + phy_opt |= HCI_LE_PHY_CODED_S2; + + if (phys & BT_PHY_LE_CODED_S8) + phy_opt |= HCI_LE_PHY_CODED_S8; + + cp_phy.phy_opt = cpu_to_le16(phy_opt); + + hci_send_cmd(conn->hdev, HCI_OP_LE_SET_PHY, sizeof(cp_phy), &cp_phy); + + hci_dev_unlock(conn->hdev); + + return 0; +} diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index c99d65ef13b1..eda5d61e37be 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -875,7 +875,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, struct bt_power pwr; struct l2cap_conn *conn; int len, err = 0; - u32 opt; + u32 opt, phys; BT_DBG("sk %p", sk); @@ -1071,6 +1071,25 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, break; + case BT_PHY: + if (sk->sk_state != BT_CONNECTED) { + err = -ENOTCONN; + break; + } + + if (copy_from_sockptr(&phys, optval, sizeof(u32))) { + err = -EFAULT; + break; + } + + err = hci_conn_set_phy(chan->conn->hcon, phys); + + if (err) + break; + + BT_DBG("phys %u", phys); + break; + case BT_MODE: if (!enable_ecred) { err = -ENOPROTOOPT; From patchwork Thu Jul 22 05:38:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Garg X-Patchwork-Id: 12393141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90764C63797 for ; Thu, 22 Jul 2021 06:00:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7453B61279 for ; Thu, 22 Jul 2021 06:00:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230286AbhGVFT0 (ORCPT ); Thu, 22 Jul 2021 01:19:26 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:48310 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230331AbhGVFTZ (ORCPT ); Thu, 22 Jul 2021 01:19:25 -0400 Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20210722060000epoutp0153cb13f14046cbb3434b426c3f520216~UB31FXRM41856418564epoutp01B for ; Thu, 22 Jul 2021 06:00:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20210722060000epoutp0153cb13f14046cbb3434b426c3f520216~UB31FXRM41856418564epoutp01B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1626933600; bh=/2228MCU1cLnBCzQ8d6CApP325OQTIV4BTpZV3hnHNw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hhA7nDA8SexnpqKqRajUehcD2XB+z+2wkOkj3oBZLIJJP3FgL6m6WASQvi3tqYSP1 tB3L04XiokS5x73MFudsPU5pQRJoX/Tkt1ahIAWSf+260SBhKMW3+pkp+B75RNXLNo vIcrrBBQW8n9CZ8HuaRgvyn4YC7McWfspVVAkL2g= Received: from epsmges5p2new.samsung.com (unknown [182.195.42.74]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20210722055959epcas5p38274291736291fb7a42cf446512b8f5d~UB30qxAge0717107171epcas5p3Z; Thu, 22 Jul 2021 05:59:59 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 54.8A.09595.E5909F06; Thu, 22 Jul 2021 14:59:58 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20210722053902epcas5p4a38e75d06dcebec336ac1b1743c1a540~UBlhqvWEZ0983809838epcas5p4b; Thu, 22 Jul 2021 05:39:02 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20210722053902epsmtrp1af3d1a8321e6dae6662408572e220396~UBlhj_QRg2559625596epsmtrp1d; Thu, 22 Jul 2021 05:39:02 +0000 (GMT) X-AuditID: b6c32a4a-ed5ff7000000257b-7f-60f9095ec2fe Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 50.D2.08394.57409F06; Thu, 22 Jul 2021 14:39:01 +0900 (KST) Received: from ayush.garg-20-10-15 (unknown [107.109.98.149]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20210722053901epsmtip236702c4e9a917bfd2895c9b841f096ce~UBlglTf2j1364013640epsmtip2j; Thu, 22 Jul 2021 05:39:00 +0000 (GMT) From: Ayush Garg To: linux-bluetooth@vger.kernel.org Cc: anupam.r@samsung.com, nitin.j@samsung.com Subject: [PATCH 3/4] Bluetooth: Add support for sending LE PHY Update event over mgmt Date: Thu, 22 Jul 2021 11:08:42 +0530 Message-Id: <20210722053843.6691-4-ayush.garg@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210722053843.6691-1-ayush.garg@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMIsWRmVeSWpSXmKPExsWy7bCmum4c588Eg647NhZ3VltbzLnWx2yx bV07swOzR9+WVYwenzfJBTBFcdmkpOZklqUW6dslcGXM3n2eqaBfpaLh2Vu2BsZ2uS5GTg4J AROJ1YdWsHYxcnEICexmlFixdQ8jhPOJUWL1zrcsEM43RokXO1tZYVoOTt8F1bKXUWL6zeUs cC0T/i9gAaliE9CUeP3xCxOILSKgLPFs32Ewm1lAV+LM+3VsILawQLjE/EVdYPUsAqoS1xe8 BLN5Bawkln2+zAKxTV5i9YYDzCA2p4C1xJzG+WwgyyQEJrNLNK76xwZR5CKx4eZSqPOEJV4d 38IOYUtJvOxvY4doaGaU2LF5I5TTwyjx4Ec3VLe9xLmmZ0DdHEDnaUqs36UPEZaVmHpqHdTV fBK9v58wQcR5JXbMg7FVJDas6oRb9vHYQmYI20Oif/8rsIOEBPoYJTZMkJ/AKDcLYcMCRsZV jJKpBcW56anFpgVGeanlesWJucWleel6yfm5mxjB8azltYPx4YMPeocYmTgYDzFKcDArifCq FH1NEOJNSaysSi3Kjy8qzUktPsQozcGiJM7LHg+UEkhPLEnNTk0tSC2CyTJxcEo1MAVmpZq4 X04smzI3fcJaib1mD+2f7jng/4rZO75moWNhzL/l1xN+yHm7PZO84eiU7pOh1MDY0/fn8aLy y5sSF7fOO2Un7Kg8L0NP6GFMTFWp4R1Vrim/29g5rQ01/S7NNpL9W6pfqcS5fc37/MbJmlvm pEysW5H4dG7AypkNy7T4F1w5emgpq43BZ3F/Czbhuyq3XSJsq7X+C++vX3uFXdvg3pM1mRNc Hrif6NW8KH9st9CitQ/lmtW/J4vUtfOtKv2/Y+mu9UtlO1MnT83OXqMQaflfOlyjY3Y+h+6K jFUyIv0t1z+nhO9aKfjJqFls2jfOBW8sLdg9Hrzx4KrekLXHPLr7i+K+yeku3rszlViKMxIN tZiLihMBeEERK1YDAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrIJMWRmVeSWpSXmKPExsWy7bCSvG4py88EgwO7TS3urLa2mHOtj9li 27p2Zgdmj74tqxg9Pm+SC2CK4rJJSc3JLEst0rdL4MqYvfs8U0G/SkXDs7dsDYztcl2MnBwS AiYSB6fvYu1i5OIQEtjNKHH6+knmLkYOoISUxONlOhA1whIr/z1nh6j5wCix+PxPVpAEm4Cm xOuPX5hAbBEBZYln+w6D2cwC+hJPL1xnBLGFBUIl9p7qAqtnEVCVuL7gJQuIzStgJbHs82UW iAXyEqs3HGAGsTkFrCXmNM5nA7lBCKhmUbvHBEa+BYwMqxglUwuKc9Nziw0LDPNSy/WKE3OL S/PS9ZLzczcxgkNFS3MH4/ZVH/QOMTJxMB5ilOBgVhLhVSn6miDEm5JYWZValB9fVJqTWnyI UZqDRUmc90LXyXghgfTEktTs1NSC1CKYLBMHp1QDU/uaA+qSB3S+vH6fdUth3qUGnzjeDUK3 edd+SSu9sXaOW62U6Y/miklSih9ePklzUDRa/Nx46d30/EQl+8qp3m/f1a0wcpwvwXI9a+NM H9eL9c/Pzp52bMITdlYV1WeyvEGJB3Skj23V8P0hPmvH0qYGG2YRE9v/69OuT1UxErldGTsl NtywjYmPQeSA6mTlI6/OLTqW1CrgvNLRb6X5rPeLmA2uyvZP1a195MK8dMbSC4zXuE/ums2+ 78FS4yUKk+478Z6oSuFlMj3y+kWm0UGrGzLqnH+7dWr8gk813JPLsN4Vf27HGjnzUr+ni5y7 w8632HTNnS3nKHfVdtvn8Ijc47ckV2eWzVhwullaS4mlOCPRUIu5qDgRAM/lLaiEAgAA X-CMS-MailID: 20210722053902epcas5p4a38e75d06dcebec336ac1b1743c1a540 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20210722053902epcas5p4a38e75d06dcebec336ac1b1743c1a540 References: <20210722053843.6691-1-ayush.garg@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org The HCI_LE_PHY_Update_Complete event should be sent to upper layers in case of autonomous PHY update made by the controller or HCI_LE_SET_PHY command succeeded. This change will let user know immediately whenever controller change LE PHYs for a particular connection. > HCI Event: LE Meta Event (0x3e) plen 6 LE PHY Update Complete (0x0c) Status: Success (0x00) Handle: 0 TX PHY: LE 2M (0x02) RX PHY: LE 2M (0x02) @ MGMT Event: LE PHY Update Complete (0x002f) plen 12 LE Address: 45:18:F8:CF:23:7E (Resolvable) Status: Success (0x00) Updated PHYs: 0x1800 LE 2M TX LE 2M RX Reviewed-by: Anupam Roy Signed-off-by: Ayush Garg --- include/net/bluetooth/hci_core.h | 1 + include/net/bluetooth/mgmt.h | 7 +++++++ net/bluetooth/hci_event.c | 11 ++++++----- net/bluetooth/mgmt.c | 34 ++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 257467f9d28d..3a5c310ec937 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1835,6 +1835,7 @@ void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev, u8 instance); void mgmt_adv_monitor_removed(struct hci_dev *hdev, u16 handle); int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip); +void mgmt_le_phy_update(struct hci_dev *hdev, struct hci_conn *conn, u8 status); int mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev, u8 status); int mgmt_remove_adv_monitor_complete(struct hci_dev *hdev, u8 status); diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h index 23a0524061b7..54800c4883fc 100644 --- a/include/net/bluetooth/mgmt.h +++ b/include/net/bluetooth/mgmt.h @@ -1100,6 +1100,13 @@ struct mgmt_ev_controller_resume { struct mgmt_addr_info addr; } __packed; +#define MGMT_EV_LE_PHY_UPDATE_COMPLETE 0x002f +struct mgmt_ev_le_phy_update_complete { + struct mgmt_addr_info addr; + __u8 status; + __le32 phys; +} __packed; + #define MGMT_WAKE_REASON_NON_BT_WAKE 0x0 #define MGMT_WAKE_REASON_UNEXPECTED 0x1 #define MGMT_WAKE_REASON_REMOTE_WAKE 0x2 diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 1c3018202564..effe525e5272 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -5970,17 +5970,18 @@ static void hci_le_phy_update_evt(struct hci_dev *hdev, struct sk_buff *skb) BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); - if (ev->status) - return; - hci_dev_lock(hdev); conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); if (!conn) goto unlock; - conn->le_tx_phy = ev->tx_phy; - conn->le_rx_phy = ev->rx_phy; + if (!ev->status) { + conn->le_tx_phy = ev->tx_phy; + conn->le_rx_phy = ev->rx_phy; + } + + mgmt_le_phy_update(hdev, conn, ev->status); unlock: hci_dev_unlock(hdev); diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 3663f880df11..683e4b66f810 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -172,6 +172,7 @@ static const u16 mgmt_events[] = { MGMT_EV_ADV_MONITOR_REMOVED, MGMT_EV_CONTROLLER_SUSPEND, MGMT_EV_CONTROLLER_RESUME, + MGMT_EV_LE_PHY_UPDATE_COMPLETE, }; static const u16 mgmt_untrusted_commands[] = { @@ -3611,6 +3612,39 @@ static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev, return err; } +void mgmt_le_phy_update(struct hci_dev *hdev, struct hci_conn *conn, + u8 status) +{ + struct mgmt_ev_le_phy_update_complete ev; + u32 phys = 0; + + memset(&ev, 0, sizeof(ev)); + + bacpy(&ev.addr.bdaddr, &conn->dst); + ev.addr.type = link_to_bdaddr(conn->type, conn->dst_type); + + ev.status = status; + + if (conn->le_tx_phy == HCI_LE_READ_PHY_1M) + phys |= MGMT_PHY_LE_1M_TX; + else if (conn->le_tx_phy == HCI_LE_READ_PHY_2M) + phys |= MGMT_PHY_LE_2M_TX; + else if (conn->le_tx_phy == HCI_LE_READ_PHY_CODED) + phys |= MGMT_PHY_LE_CODED_TX; + + if (conn->le_rx_phy == HCI_LE_READ_PHY_1M) + phys |= MGMT_PHY_LE_1M_RX; + else if (conn->le_rx_phy == HCI_LE_READ_PHY_2M) + phys |= MGMT_PHY_LE_2M_RX; + else if (conn->le_rx_phy == HCI_LE_READ_PHY_CODED) + phys |= MGMT_PHY_LE_CODED_RX; + + ev.phys = cpu_to_le32(phys); + + mgmt_event(MGMT_EV_LE_PHY_UPDATE_COMPLETE, hdev, &ev, sizeof(ev), + NULL); +} + static int set_blocked_keys(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) { From patchwork Thu Jul 22 05:38:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Garg X-Patchwork-Id: 12393143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C83FCC63793 for ; Thu, 22 Jul 2021 06:00:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF4956127C for ; Thu, 22 Jul 2021 06:00:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230357AbhGVFTc (ORCPT ); Thu, 22 Jul 2021 01:19:32 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:48406 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230343AbhGVFTa (ORCPT ); Thu, 22 Jul 2021 01:19:30 -0400 Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20210722060005epoutp01c72823610515a02eac63e93e00e8a2a1~UB35wmVoN1867618676epoutp016 for ; Thu, 22 Jul 2021 06:00:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20210722060005epoutp01c72823610515a02eac63e93e00e8a2a1~UB35wmVoN1867618676epoutp016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1626933605; bh=pVu3zbdh7GNV1/bjbNgLaeBeBsSatd1pBebiBnWSZQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q6lYubgxQIuMHnu6QsBi6ofkLgXGrNyyZpBwXs7vFGXgywAsOBTyIqqxU/fR3NJ7b JqZhGcLS4CvZmOpXAlYm4FmZ55TDi7W/iO+euMOZ0T3/tKQMyU7tn2oKugzVfqvQ+5 OpUk8OLQ7KljAOfEbk1QCWjIJO71uQA6lZO9ubxY= Received: from epsmges5p2new.samsung.com (unknown [182.195.42.74]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20210722060003epcas5p2216baa8a9d1318fcb40fc42b0fb16cd0~UB34J_5Ul0442304423epcas5p2D; Thu, 22 Jul 2021 06:00:03 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 38.8A.09595.26909F06; Thu, 22 Jul 2021 15:00:02 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20210722053903epcas5p4e25daf9341dca446a0fbfd7b5d54324c~UBlis2u582580025800epcas5p4P; Thu, 22 Jul 2021 05:39:03 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20210722053903epsmtrp22ed007e7e05744f7c9348c2e4e0cf6a2~UBlimK_eo0680906809epsmtrp26; Thu, 22 Jul 2021 05:39:03 +0000 (GMT) X-AuditID: b6c32a4a-ed5ff7000000257b-8d-60f909626f04 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 7D.1A.08289.67409F06; Thu, 22 Jul 2021 14:39:03 +0900 (KST) Received: from ayush.garg-20-10-15 (unknown [107.109.98.149]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20210722053902epsmtip2d9f9c6699a9243cb9089c2af2b3128ee~UBlhw-Lf71363413634epsmtip2o; Thu, 22 Jul 2021 05:39:02 +0000 (GMT) From: Ayush Garg To: linux-bluetooth@vger.kernel.org Cc: anupam.r@samsung.com, nitin.j@samsung.com Subject: [PATCH 4/4] Bluetooth: Update LE TX & RX PHYs when connection established Date: Thu, 22 Jul 2021 11:08:43 +0530 Message-Id: <20210722053843.6691-5-ayush.garg@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210722053843.6691-1-ayush.garg@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMIsWRmVeSWpSXmKPExsWy7bCmlm4S588Eg/bPVhZ3VltbzLnWx2yx bV07swOzR9+WVYwenzfJBTBFcdmkpOZklqUW6dslcGWce3SXteCtQsXXK8fYGhi3SXUxcnJI CJhI7L4xnb2LkYtDSGA3o8SZtVtZQRJCAp8YJWY8j4BIfGaU+LZnIjNMR8vLeUwQiV2MElcv HGaFcIA6tnXOAmtnE9CUeP3xCxOILSKgLPFs32Ewm1lAV+LM+3VsILawQIjE50eLwOIsAqoS Dx88ZAexe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PDKkbJ1ILi3PTcYsMCo7zUcr3ixNzi0rx0veT8 3E2M4DDR0trBuGfVB71DjEwcjIcYJTiYlUR4VYq+JgjxpiRWVqUW5ccXleakFh9ilOZgURLn vdB1Ml5IID2xJDU7NbUgtQgmy8TBKdXAVDDBZue2koKnLgsn7Wd5lm3O+vV/1omtS6JeGX60 PRX46uVKE/7pT/1Ph1xR635+40y5S5ndmsizlzlmXPnJNIuz6Ffzrs64hVk2rmlPJlcte3Dx Wm4VW1/62/Oq4bYx62ruyK+2KPsY4DJvlv5u3x+fZ+oIbpq7bZb4bwE2tj/3GdbMv3nHaEqO 566/X36J6ayQn6G4YBfzv5I5LhY/L+5cvUit5nBPtZz7ylNdc2f7iRtZyoTd/LV3dfScFJPW i3Gv3u9af8tOYqN60rF332aF2xRPuyQQlWf3sV7aPb3pie9n3/lnbzVEHLHg8InWfvJnz7k3 8m/vsNT7XZXz5P+hn+CnVyvH88/douLETz4lluKMREMt5qLiRAAs/g0KggIAAA== X-CMS-MailID: 20210722053903epcas5p4e25daf9341dca446a0fbfd7b5d54324c X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20210722053903epcas5p4e25daf9341dca446a0fbfd7b5d54324c References: <20210722053843.6691-1-ayush.garg@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org The TX and RX PHYs will always be 1M if the established LE connection is a legacy connection. These values may differ in case of LE Extended connection. This change will read and update the connection PHYs and autonomously send LE PHY Update event if the connection is LE Extended. < HCI Command: LE Read PHY (0x08|0x0030) plen 2 Handle: 0 > HCI Event: Command Complete (0x0e) plen 8 LE Read PHY (0x08|0x0030) ncmd 1 Status: Success (0x00) Handle: 0 TX PHY: LE 1M (0x01) RX PHY: LE 1M (0x01) @ MGMT Event: LE PHY Update Complete (0x002f) plen 12 LE Address: 45:18:F8:CF:23:7E (Resolvable) Status: Success (0x00) Updated PHYs: 0x0600 LE 1M TX LE 1M RX Reviewed-by: Anupam Roy Signed-off-by: Ayush Garg --- include/net/bluetooth/hci.h | 12 +++++++++ net/bluetooth/hci_event.c | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 06e10ccf2a1c..6073e8431ed5 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -1670,6 +1670,18 @@ struct hci_rp_le_read_max_data_len { __le16 rx_time; } __packed; +#define HCI_OP_LE_READ_PHY 0x2030 +struct hci_cp_le_read_phy { + __le16 handle; +} __packed; + +struct hci_rp_le_read_phy { + __u8 status; + __le16 handle; + __u8 tx_phy; + __u8 rx_phy; +} __packed; + #define HCI_OP_LE_SET_DEFAULT_PHY 0x2031 struct hci_cp_le_set_default_phy { __u8 all_phys; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index effe525e5272..37ab2f2a1d06 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1196,6 +1196,31 @@ static void hci_cc_le_set_default_phy(struct hci_dev *hdev, struct sk_buff *skb) hci_dev_unlock(hdev); } +static void hci_cc_le_read_phy(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct hci_rp_le_read_phy *rp = (void *)skb->data; + struct hci_conn *conn; + + BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); + + if (rp->status) + return; + + hci_dev_lock(hdev); + + conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); + if (!conn) + goto unlock; + + conn->le_tx_phy = rp->tx_phy; + conn->le_rx_phy = rp->rx_phy; + + mgmt_le_phy_update(hdev, conn, 0); + +unlock: + hci_dev_unlock(hdev); +} + static void hci_cc_le_set_adv_set_random_addr(struct hci_dev *hdev, struct sk_buff *skb) { @@ -3642,6 +3667,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, hci_cc_le_read_transmit_power(hdev, skb); break; + case HCI_OP_LE_READ_PHY: + hci_cc_le_read_phy(hdev, skb); + break; + default: BT_DBG("%s opcode 0x%4.4x", hdev->name, *opcode); break; @@ -5229,6 +5258,17 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, goto unlock; } + /* If this LE connection is not an extended connection, then LE + * PHYs will always be 1M at the time of connection establishment. + * So, set 1M as initial LE PHY values. + * But if this is LE Extended connection, then the PHY values + * can be 1M, 2M or CODED. So, In this case, read and update + * the values after the conn->state becomes connected and + * then, send the LE_PHY_UPDATE_COMPLETE event. + */ + conn->le_tx_phy = HCI_LE_SET_PHY_1M; + conn->le_rx_phy = HCI_LE_SET_PHY_1M; + if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) mgmt_device_connected(hdev, conn, NULL, 0); @@ -5267,6 +5307,17 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, hci_connect_cfm(conn, status); } + /* If this is LE Extended connection and HCI_LE_READ_PHY + * command is supported, then update the LE PHYs. + */ + if (use_ext_conn(hdev) && hdev->commands[35] & 0x10) { + struct hci_cp_le_read_phy cp; + + cp.handle = __cpu_to_le16(conn->handle); + + hci_send_cmd(hdev, HCI_OP_LE_READ_PHY, sizeof(cp), &cp); + } + params = hci_pend_le_action_lookup(&hdev->pend_le_conns, &conn->dst, conn->dst_type); if (params) {