Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17662941ybl; Thu, 2 Jan 2020 09:36:38 -0800 (PST) X-Google-Smtp-Source: APXvYqwy54vG2paFJ+Z/nZUOsCgd3RGHoFRFwBE0NlvIVvLdlQUaE5NHn+baE94RFoMas3nUbjK7 X-Received: by 2002:a9d:5885:: with SMTP id x5mr91165844otg.132.1577986598887; Thu, 02 Jan 2020 09:36:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577986598; cv=none; d=google.com; s=arc-20160816; b=PsemLjREzDFvArq2gG4DnotdLzO46uC2xJv/QWfFkgXp5WIfL93A0XsFmkf9237uC9 3yfBxuuPhmlTr0HkWsme9MWP7vUv4HlrZX/ZnA+wJ+XJgob5uEgK08zlX06wo19VGxrR 1xcXBGE7Ja4OP1Is5rvFLvLa9scQI18TdFagDF7wGVg19nW0bYGmEgkcoF/mru0h0u6R odJeHF/vDZZvU1gdG3mL7sZ04L8/rNKHTXOM/4ptCsS88/Az5u/qNGL8hAuRw90+gdN5 a1aPZ9bAs1NNTIj5BY47nzikTfHwNLic+aWZE9gnTaLlv3V6fRjLLAlAywGg+zzSz8Zz o5+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=n7Suy5vm7eNETKI9A6AINZMUiCvIq8nyXo0HCt+zKP8=; b=x6U2bbc+4nRsBv6ekqKfEmb5gAiN7A+B+WTtOGBD5/bWJ+MrhGbtSGU5ikEXzBXkgS gmNba52+X4y5bX3LFfOdXZaHJfY/d0ZxrQZEOi58cxgYfhrkS0JoWhexIxh8BwKNmp8w trvlGatZ2/qVPx+JXssxNlbilSmhLaJ+JvSFKgIsBxzcyNXp+W1u7HkQdY/GMoWQ0dgJ iT4Gnd3np/u7D5H1MQ4X9VHBjHKbjEwexaGmqwv13FM87X9o8LRUJPyDzdwBvrtnrbsv ecdhzHd+1+HMcCtAWCISAH7lryspYFm1YCbuiwuKDsnNuffKWw81VK3fXCMzr9lvVdOX 8S4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HXtjKlq1; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s68si27669418oih.275.2020.01.02.09.36.20; Thu, 02 Jan 2020 09:36:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HXtjKlq1; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 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 S1727755AbgABRgU (ORCPT + 99 others); Thu, 2 Jan 2020 12:36:20 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:33285 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727706AbgABRgT (ORCPT ); Thu, 2 Jan 2020 12:36:19 -0500 Received: by mail-ot1-f66.google.com with SMTP id b18so36098574otp.0 for ; Thu, 02 Jan 2020 09:36:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=n7Suy5vm7eNETKI9A6AINZMUiCvIq8nyXo0HCt+zKP8=; b=HXtjKlq1jsrjoLsiorB8J3pxdvE1zHIta1XdTHa2wyVwinm8p79R27QcACVqS0PbxR WFky8Hx9Bh5bH03BhvBvrEgQr0QblJHN7Kok9ccnfrHf1zGjQx/Mv84EeFD7kLoXB7u2 JSwYRzJ5MBuyL162jH8TbKgkAhZuLxEbSgL+9w63l3e4G6854bADn/NE1NfszTrG1jgM HORp6akjkAjCK59GSnL6zr3GHk1ols2bAfBtuK7XscLmwCsrNzZLlAdq5QpBtT6ttF4R 63LrsHMTgjOGGW97kYfeZ4MWDH2ql7Wdr+TpXwyvgBsG6FXxI0g5Owjim0Xc6T+6+G3z xkuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=n7Suy5vm7eNETKI9A6AINZMUiCvIq8nyXo0HCt+zKP8=; b=CO3EQkLVbkVAkKwBFK9b7K5ACGLTQWd3ZCmZ3jjGBXenS1F+XjnSAoeQVKR8lvtJ6C CzRMZ9KvenDXoCKJwmjEjmC2twGalrPZHs6TRTvM/+vamIE9dEwXglGl6wMabmAgDBsb dfSIxldHOT15zX80SbgxET+t53nawQvKBkT6z0nEmJyh7WTWQeExcAivaaxTkMAFLdjI vO3Y3dUeCqUSCh7KplCX5LIwaUlan7Wm4IkIa0SHhYDZWlCwMQ8kscSUTTwydFp069oq byxTNAL8Xj2aYJbwwSrVzj7NiS08mMZ2uLj4FA7C3uZQ2ZK1X8IA/F/C1ZzpYhLD4Zhp 4IwQ== X-Gm-Message-State: APjAAAWuPXrXnV/ZJIeD2fiie6ES+McSHmAelIgbyCgs4FLriAGEG1SG +h1nucE0G+neHAAJCnw/mVsJCL1As4+hzmaKtwGt0nJ2 X-Received: by 2002:a9d:6d10:: with SMTP id o16mr95414476otp.28.1577986578189; Thu, 02 Jan 2020 09:36:18 -0800 (PST) MIME-Version: 1.0 References: <20200102172447.18574-1-luiz.dentz@gmail.com> <20200102172447.18574-2-luiz.dentz@gmail.com> In-Reply-To: <20200102172447.18574-2-luiz.dentz@gmail.com> From: Luiz Augusto von Dentz Date: Thu, 2 Jan 2020 09:36:06 -0800 Message-ID: Subject: Re: [RFC 2/2] Bluetooth: Add BT_PHYS socket option To: "linux-bluetooth@vger.kernel.org" Cc: =?UTF-8?Q?Pali_Roh=C3=A1r?= Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Pali, On Thu, Jan 2, 2020 at 9:24 AM Luiz Augusto von Dentz wrote: > > From: Luiz Augusto von Dentz > > This adds BT_PHYS socket option which can be used to read the PHYs in > use by the underline connection. > > Signed-off-by: Luiz Augusto von Dentz > --- > include/net/bluetooth/bluetooth.h | 17 ++++++++ > include/net/bluetooth/hci_core.h | 2 + > net/bluetooth/hci_conn.c | 64 +++++++++++++++++++++++++++++++ > net/bluetooth/l2cap_sock.c | 13 +++++++ > net/bluetooth/sco.c | 13 +++++++ > 5 files changed, 109 insertions(+) > > diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h > index e42bb8e03c09..69c0e7eb26d9 100644 > --- a/include/net/bluetooth/bluetooth.h > +++ b/include/net/bluetooth/bluetooth.h > @@ -121,6 +121,23 @@ struct bt_voice { > > #define BT_SNDMTU 12 > #define BT_RCVMTU 13 > +#define BT_PHYS 14 > + > +#define BT_PHY_BR_1M_1SLOT 0x00000001 > +#define BT_PHY_BR_1M_3SLOT 0x00000002 > +#define BT_PHY_BR_1M_5SLOT 0x00000004 > +#define BT_PHY_EDR_2M_1SLOT 0x00000008 > +#define BT_PHY_EDR_2M_3SLOT 0x00000010 > +#define BT_PHY_EDR_2M_5SLOT 0x00000020 > +#define BT_PHY_EDR_3M_1SLOT 0x00000040 > +#define BT_PHY_EDR_3M_3SLOT 0x00000080 > +#define BT_PHY_EDR_3M_5SLOT 0x00000100 > +#define BT_PHY_LE_1M_TX 0x00000200 > +#define BT_PHY_LE_1M_RX 0x00000400 > +#define BT_PHY_LE_2M_TX 0x00000800 > +#define BT_PHY_LE_2M_RX 0x00001000 > +#define BT_PHY_LE_CODED_TX 0x00002000 > +#define BT_PHY_LE_CODED_RX 0x00004000 This might be of your interest since you wanted to know what packet size to use, we might use this to adjust the MTU automatically instead of always using 672 so we maximize the throughput if the socket owner has not set a MTU on its own. > __printf(1, 2) > void bt_info(const char *fmt, ...); > diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h > index faebe3859931..03cf3f0f22b9 100644 > --- a/include/net/bluetooth/hci_core.h > +++ b/include/net/bluetooth/hci_core.h > @@ -1467,6 +1467,8 @@ void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode); > struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, > const void *param, u32 timeout); > > +u32 hci_conn_get_phys(struct hci_conn *conn); > + > /* ----- HCI Sockets ----- */ > void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb); > void hci_send_to_channel(unsigned short channel, struct sk_buff *skb, > diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c > index 87691404d0c6..386e6b0bd2ab 100644 > --- a/net/bluetooth/hci_conn.c > +++ b/net/bluetooth/hci_conn.c > @@ -1725,3 +1725,67 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle) > > return hchan; > } > + > +u32 hci_conn_get_phys(struct hci_conn *conn) > +{ > + u32 phys = 0; > + > + hci_dev_lock(conn->hdev); > + > + switch (conn->type) { > + case ACL_LINK: > + case SCO_LINK: > + phys |= BT_PHY_BR_1M_1SLOT; > + > + if (conn->pkt_type & (HCI_DM3 | HCI_DH3)) > + phys |= BT_PHY_BR_1M_3SLOT; > + > + if (conn->pkt_type & (HCI_DM5 | HCI_DH5)) > + phys |= BT_PHY_BR_1M_5SLOT; > + > + if (!(conn->pkt_type & HCI_2DH1)) > + phys |= BT_PHY_EDR_2M_1SLOT; > + > + if (!(conn->pkt_type & HCI_2DH3)) > + phys |= BT_PHY_EDR_2M_3SLOT; > + > + if (!(conn->pkt_type & HCI_2DH5)) > + phys |= BT_PHY_EDR_2M_5SLOT; > + > + if (!(conn->pkt_type & HCI_3DH1)) > + phys |= BT_PHY_EDR_3M_1SLOT; > + > + if (!(conn->pkt_type & HCI_3DH3)) > + phys |= BT_PHY_EDR_3M_3SLOT; > + > + if (!(conn->pkt_type & HCI_3DH5)) > + phys |= BT_PHY_EDR_3M_5SLOT; > + > + 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) > + 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) > + phys |= BT_PHY_LE_CODED_TX; > + > + if (conn->le_rx_phy & HCI_LE_SET_PHY_CODED) > + phys |= BT_PHY_LE_CODED_RX; > + > + break; > + } > + > + hci_dev_unlock(conn->hdev); > + > + return phys; > +} > diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c > index a7be8b59b3c2..fb011c6c67be 100644 > --- a/net/bluetooth/l2cap_sock.c > +++ b/net/bluetooth/l2cap_sock.c > @@ -499,6 +499,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, > struct l2cap_chan *chan = l2cap_pi(sk)->chan; > struct bt_security sec; > struct bt_power pwr; > + u32 phys; > int len, err = 0; > > BT_DBG("sk %p", sk); > @@ -603,6 +604,18 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, > err = -EFAULT; > break; > > + case BT_PHYS: > + if (sk->sk_state == BT_CONNECTED) { > + err = -EINVAL; > + break; > + } > + > + phys = hci_conn_get_phys(chan->conn->hcon); > + > + if (put_user(phys, (u32 __user *) optval)) > + err = -EFAULT; > + break; > + > default: > err = -ENOPROTOOPT; > break; > diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c > index b91d6b440fdf..dcd297f2acc6 100644 > --- a/net/bluetooth/sco.c > +++ b/net/bluetooth/sco.c > @@ -922,6 +922,7 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, > struct sock *sk = sock->sk; > int len, err = 0; > struct bt_voice voice; > + u32 phys; > > BT_DBG("sk %p", sk); > > @@ -956,6 +957,18 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, > > break; > > + case BT_PHYS: > + if (sk->sk_state == BT_CONNECTED) { > + err = -EINVAL; > + break; > + } > + > + phys = hci_conn_get_phys(sco_pi(sk)->conn->hcon); > + > + if (put_user(phys, (u32 __user *) optval)) > + err = -EFAULT; > + break; > + > default: > err = -ENOPROTOOPT; > break; > -- > 2.21.0 > -- Luiz Augusto von Dentz