Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17681349ybl; Thu, 2 Jan 2020 09:59:44 -0800 (PST) X-Google-Smtp-Source: APXvYqyzdjK99Ugkbf76u09A8TUSAkf3Xdx6L8X6M+WLDmF/RlQOjCR5n2q7oC3kJIoyWUDjLmsD X-Received: by 2002:a05:6830:1cc9:: with SMTP id p9mr68005863otg.59.1577987984590; Thu, 02 Jan 2020 09:59:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577987984; cv=none; d=google.com; s=arc-20160816; b=ycniOWAGGTHkKaONB5Gm2syyFirfHnlEwe/Whf4hw+882w4T4ClO4ibhZiIrWl39Zn Q4DewtVuIqTh1Jnw53JiH8A3h2jseBIgJlB4KGuDN8OP6IK/kZ7dhTVGdcnpjC8di5Ex Nwk2ZWTC24LkQsRcCNSeU6Ek33DntBKl50TlQx+nXt4e8JnL3N/076j8Ya2DnSa+agv5 tN2yYV4L1Tz1zDFspCWYvY4X3WUeigUuSos1y8EbM3Dnbuo8uDyMEbgfimLHd9qb6fLN nmOfnwPFiZoMwbBRvR4VZ+TimdBe2us+Kj3h8IUezcx3fPp75yLFJIHgGNn0XnVyL2rT 3naw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ZWyy8HbMfg3rrzbup8n1LY4TMLq8EO7riOX5eoG3n58=; b=flAPjGr2MGv2ADjIvOtlUn0EkXI+RfRg+eaRxzfaAbmmxgX2AEVvgaF/+qu40WwaaA INHtWF+8O1vDMRvLWY63SN2AMnJrywDeYCheuV/BwZozLK5eo7WayhamBw5ybkYrqB5l n9OXBmu65NyXN0M4qie7wCQxUFdHN0IY36vzmo6S6f+jLmXI23yCf/UDf0uhJ2tUfJWM zhHQ7/8px0WT1tvwab/fXbcCnj4fhX8jYTxu2gd/IT5cDtE4xL+3wV/17XrBlCUpufEK KBhHj3AnLM7RiHzC3gslUiWtgq6ZHD+Craxkiianor/DOephjhLM/DDSBrh6oX7tVyo+ eiSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dv4eDW3E; 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 z1si29163905otm.242.2020.01.02.09.59.31; Thu, 02 Jan 2020 09:59:44 -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=dv4eDW3E; 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 S1727829AbgABR7a (ORCPT + 99 others); Thu, 2 Jan 2020 12:59:30 -0500 Received: from mail-ot1-f67.google.com ([209.85.210.67]:45486 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727755AbgABR7a (ORCPT ); Thu, 2 Jan 2020 12:59:30 -0500 Received: by mail-ot1-f67.google.com with SMTP id 59so58019897otp.12 for ; Thu, 02 Jan 2020 09:59:29 -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:content-transfer-encoding; bh=ZWyy8HbMfg3rrzbup8n1LY4TMLq8EO7riOX5eoG3n58=; b=dv4eDW3EUh2RrGBgFS7UmIdvF6/Qa1q1jwGxRxgLsi6Rqo7lL2bDk38nCaxUzjsx0z /Q3bkORD76QXe2BQ17/5NkMHhz5Sewlj1VuZDhlUfxRGlaahmu1nHSIHbkG85GPOcf52 8/e0j9VvfN3lI8rxtu/77NWJc9r3D7pEcB8X7mMtEDIEg6jfw9iElC2ymcum6c8czcz1 PHAqQkEG9YprB0olQ2+m9KVafnqBL3gaKeLB9qoEf2d7MGINWo2XpXkQSaE8joKWlFjA 9uPm4/ABG2KLbbhW2z26H+8tECwMj3mCS+2tVuZNHp78UYnGpbguqxafm4/TTY9cPeoM DI5A== 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:content-transfer-encoding; bh=ZWyy8HbMfg3rrzbup8n1LY4TMLq8EO7riOX5eoG3n58=; b=Hj0GBQD/XIcVVxJM6cjKADz1qoQyAP8sFAedtGWiWWNc8c2M7HY8UNw5EgF1YxSrcJ VRxbjYluUNH8Pj05z4aj2EJhddh6wmcb5EPM5fOhu0L/JGIVtp+OBp3jvhHjBNaxLF1E JwYiKFs5yHxL4x14YzGeGXzzza2ZReXc4S37gvVhGif19HdvyZj/UhCg20Op9js51jJw 184jUszd0XWIu0jeBl9scuPU7PVOttVExJLYJfWziQXYlzlW1aMjd8QX6CGuLSUPpYsh uBlua7NQliY2uZ0ZUoedS2gsA8no9tx2/v7I5aCl6ad0slCwMYXl3RXah7S3E6MDtijy dPSw== X-Gm-Message-State: APjAAAU86jGnoh+xafmsXAp371dfsAN7/sUIA5ZTCxQpVOl9JIVHdBgO Vc8MiRhoxXR87QXVMjTuHVaOrnTRy3GqPIs9tswOoD8Y X-Received: by 2002:a9d:6d10:: with SMTP id o16mr95514231otp.28.1577987968580; Thu, 02 Jan 2020 09:59:28 -0800 (PST) MIME-Version: 1.0 References: <20200102172447.18574-1-luiz.dentz@gmail.com> <20200102172447.18574-2-luiz.dentz@gmail.com> <20200102175000.wefojdsgqo7q35pt@pali> In-Reply-To: <20200102175000.wefojdsgqo7q35pt@pali> From: Luiz Augusto von Dentz Date: Thu, 2 Jan 2020 09:59:16 -0800 Message-ID: Subject: Re: [RFC 2/2] Bluetooth: Add BT_PHYS socket option To: =?UTF-8?Q?Pali_Roh=C3=A1r?= Cc: "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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:50 AM Pali Roh=C3=A1r wrote= : > > 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 > > 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/bluetoot= h/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? Afaik BT_SNDMTU/BT_RCVMTU are the options that shall be used to adjust the MTU, what Im suggesting is to do it automatically if the socket owner has not set anything, perhaps you are asking if that would be possible to read the default MTU, yes that would work exactly as it is right now so we don't have to change anything in userspace, though the is another detail to consider that is if the MTU actually fits into the HCI buffer otherwise we would have to fragment the packets in multiple HCI fragments which kind defeat the purpose of having such big MTU, for LE is actually simpler since we have the actual MTU used in the connection. > > > __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 p= len, > > > 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 =3D 0; > > > + > > > + hci_dev_lock(conn->hdev); > > > + > > > + switch (conn->type) { > > > + case ACL_LINK: > > > + case SCO_LINK: > > > + phys |=3D BT_PHY_BR_1M_1SLOT; > > > + > > > + if (conn->pkt_type & (HCI_DM3 | HCI_DH3)) > > > + phys |=3D BT_PHY_BR_1M_3SLOT; > > > + > > > + if (conn->pkt_type & (HCI_DM5 | HCI_DH5)) > > > + phys |=3D BT_PHY_BR_1M_5SLOT; > > > + > > > + if (!(conn->pkt_type & HCI_2DH1)) > > > + phys |=3D BT_PHY_EDR_2M_1SLOT; > > > + > > > + if (!(conn->pkt_type & HCI_2DH3)) > > > + phys |=3D BT_PHY_EDR_2M_3SLOT; > > > + > > > + if (!(conn->pkt_type & HCI_2DH5)) > > > + phys |=3D BT_PHY_EDR_2M_5SLOT; > > > + > > > + if (!(conn->pkt_type & HCI_3DH1)) > > > + phys |=3D BT_PHY_EDR_3M_1SLOT; > > > + > > > + if (!(conn->pkt_type & HCI_3DH3)) > > > + phys |=3D BT_PHY_EDR_3M_3SLOT; > > > + > > > + if (!(conn->pkt_type & HCI_3DH5)) > > > + phys |=3D BT_PHY_EDR_3M_5SLOT; > > > + > > > + break; > > > + > > > + case LE_LINK: > > > + if (conn->le_tx_phy & HCI_LE_SET_PHY_1M) > > > + phys |=3D BT_PHY_LE_1M_TX; > > > + > > > + if (conn->le_rx_phy & HCI_LE_SET_PHY_1M) > > > + phys |=3D BT_PHY_LE_1M_RX; > > > + > > > + if (conn->le_tx_phy & HCI_LE_SET_PHY_2M) > > > + phys |=3D BT_PHY_LE_2M_TX; > > > + > > > + if (conn->le_rx_phy & HCI_LE_SET_PHY_2M) > > > + phys |=3D BT_PHY_LE_2M_RX; > > > + > > > + if (conn->le_tx_phy & HCI_LE_SET_PHY_CODED) > > > + phys |=3D BT_PHY_LE_CODED_TX; > > > + > > > + if (conn->le_rx_phy & HCI_LE_SET_PHY_CODED) > > > + phys |=3D 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 *s= ock, int level, int optname, > > > struct l2cap_chan *chan =3D l2cap_pi(sk)->chan; > > > struct bt_security sec; > > > struct bt_power pwr; > > > + u32 phys; > > > int len, err =3D 0; > > > > > > BT_DBG("sk %p", sk); > > > @@ -603,6 +604,18 @@ static int l2cap_sock_getsockopt(struct socket *= sock, int level, int optname, > > > err =3D -EFAULT; > > > break; > > > > > > + case BT_PHYS: > > > + if (sk->sk_state =3D=3D BT_CONNECTED) { > > > + err =3D -EINVAL; > > > + break; > > > + } > > > + > > > + phys =3D hci_conn_get_phys(chan->conn->hcon); > > > + > > > + if (put_user(phys, (u32 __user *) optval)) > > > + err =3D -EFAULT; > > > + break; > > > + > > > default: > > > err =3D -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 *soc= k, int level, int optname, > > > struct sock *sk =3D sock->sk; > > > int len, err =3D 0; > > > struct bt_voice voice; > > > + u32 phys; > > > > > > BT_DBG("sk %p", sk); > > > > > > @@ -956,6 +957,18 @@ static int sco_sock_getsockopt(struct socket *so= ck, int level, int optname, > > > > > > break; > > > > > > + case BT_PHYS: > > > + if (sk->sk_state =3D=3D BT_CONNECTED) { > > > + err =3D -EINVAL; > > > + break; > > > + } > > > + > > > + phys =3D hci_conn_get_phys(sco_pi(sk)->conn->hcon); > > > + > > > + if (put_user(phys, (u32 __user *) optval)) > > > + err =3D -EFAULT; > > > + break; > > > + > > > default: > > > err =3D -ENOPROTOOPT; > > > break; > > > -- > > > 2.21.0 > > > > > > > > > -- > Pali Roh=C3=A1r > pali.rohar@gmail.com --=20 Luiz Augusto von Dentz