From: "Pali Rohár" <pali.rohar@gmail.com>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: Re: [RFC 2/2] Bluetooth: Add BT_PHYS socket option
Date: Thu, 2 Jan 2020 18:50:00 +0100 [thread overview]
Message-ID: <20200102175000.wefojdsgqo7q35pt@pali> (raw)
In-Reply-To: <CABBYNZJXvmF8j8Fd=zkr0a83RQ52OeEcbTJk-bgk3R9Ofzq8AA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 7993 bytes --]
On Thursday 02 January 2020 09:36:06 Luiz Augusto von Dentz wrote:
> Hi Pali,
>
> On Thu, Jan 2, 2020 at 9:24 AM Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
> >
> > From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> >
> > 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 <luiz.von.dentz@intel.com>
> > ---
> > 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.
Great! Thank you for information.
Would getsockopt(sock, SOL_L2CAP, L2CAP_OPTIONS, ...) call returns also
adjusted MTU value?
> > __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
> >
>
>
--
Pali Rohár
pali.rohar@gmail.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
next prev parent reply other threads:[~2020-01-02 17:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-02 17:24 [RFC 1/2] Bluetooth: HCI: Add support for LE PHY Update Complete event Luiz Augusto von Dentz
2020-01-02 17:24 ` [RFC 2/2] Bluetooth: Add BT_PHYS socket option Luiz Augusto von Dentz
2020-01-02 17:36 ` Luiz Augusto von Dentz
2020-01-02 17:50 ` Pali Rohár [this message]
2020-01-02 17:59 ` Luiz Augusto von Dentz
2020-01-03 7:22 ` Jamie Mccrae
2020-01-03 17:45 ` Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200102175000.wefojdsgqo7q35pt@pali \
--to=pali.rohar@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox