Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp276281pxv; Wed, 21 Jul 2021 23:00:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvGlXBhHS5wtf0jgvuFclV8y6CblZpRtOht1X6i0+CKwEMlrITB7NkXQ50sbtm5QqRQmN1 X-Received: by 2002:a05:6e02:52d:: with SMTP id h13mr25395464ils.119.1626933659592; Wed, 21 Jul 2021 23:00:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626933659; cv=none; d=google.com; s=arc-20160816; b=E7nFmZgXpJ3OSNL4xfSS70dHel6koTk7XtDYWxbyoAAr2P9bi0sNMGkZLyAOL1tqu8 s8nohvGATMGMAL7r0PfUx2MNyWD/xrninUITX0FH526hIEbVr+oPDToh35/X5iinZRsu /CyER4tpBxJSim2CQzf+mRxNzAAkq5NiEunZPzHoLN6uVb0PqhAJfFY87084Wtt2I/e3 tXcgM2jSm/u/8sfvS/Z/Q3VoYxvP3D0dqI9daCEmAf2no1trJs2CnSyrJeTErf2n7XPd nOnNWmPJGmsN7DDSF9q6TVokMGrdLVuFY7rArv05Uazgij0dFCcfkW2/QjBNKh3dCe5L weNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=lPkysQYmSXHnQUX3l0i1LE71r9ldEKU/cKhT+tvmFus=; b=yY3Xm29e+NTqAeWl7ws3aXCUTNAE+i5hzRYrYyD9d2RxE4cqVJshiLSGWMXY6BqUTM reLoS+vinhgqL6LJxQq3+cM7dzlVUf3ypd5UllZWqbRMGmn+frvYlrjqCjGw2kC0LzTK hwR0zQF5Jhqpe54I2EEKZ/8cSqEWP84TDAdnV51LvtRgqOUT9LNzkMJrMW4kRMLXiLp/ GE1UfxpqYfYMmvbilU2ILWG6LNH0WDJqBhi2CnrqMw9VBEKhCRHON2P1cO6+7WR+Ea/G DYsTJGrayBjPnTR/hCZFuIFLMX6WQJB9UHkMqEgbe9ZtbCC11PbuSCrtkRZRejHmC/5R gNQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=cuVMzmF5; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y13si22347844ilu.34.2021.07.21.23.00.33; Wed, 21 Jul 2021 23:00:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=cuVMzmF5; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230283AbhGVFTY (ORCPT + 99 others); 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/fCAS3xgl5j26zwbTcaGliRkisZdR4s+8 W4wQDlDHhOtLwdrZBDQlXn/8AmaLCChLPNt3GMxmFtCVOPN+HdAkDg5hAUeJPWs8QMIsAqoS 9ze9ZgGxeQWsJNY2X2SGWCYvsXrDATCbU8BaYk7jfDaQXRICk9klet/1QBW5SPQv2sAEYQtL vDq+hR3ClpJ42d/GDtHQzCixY/NGKKeHUeLBj26of+wlzjU9YwW5iBno6vW79CHCshJTT62D OppPovf3E6gFvBI75sHYKhIbVnXCLft4bCHUQR4Sq5Y9Y4aEYx+jxLn5dRMY5WYhbFjAyLiK UTK1oDg3PbXYtMA4L7Vcrzgxt7g0L10vOT93EyM4lrW8dzA+evBB7xAjEwfjIUYJDmYlEV6V oq8JQrwpiZVVqUX58UWlOanFhxilOViUxHnZ44FSAumJJanZqakFqUUwWSYOTqkGptkeRw68 O9cUXy7Bl6LBNuGSfa6O2iRm7p83yz4u7xTMXVS0syfEiOeX7xzNCwXXfjDNU+Z4eOhmVfus WTa7GKpUnjE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a9VBVbd6n0sW1Rs3xi3rZTdWXaX+o3L8zY +9PiwnnXOSq52dvn13dLT699cCXzSqVP8uFDnPO5lViKMxINtZiLihMB1fGE3YMCAAA= X-CMS-MailID: 20210722053900epcas5p48430eb1335c3e566be02135e63749f33 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" 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; -- 2.17.1