* [PATCH] Bluetooth: Add BT_PHY socket option
@ 2020-02-07 19:00 Luiz Augusto von Dentz
2020-02-08 8:32 ` Marcel Holtmann
0 siblings, 1 reply; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2020-02-07 19:00 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds BT_PHY socket option (read-only) 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 | 88 +++++++++++++++++++++++++++++++
net/bluetooth/l2cap_sock.c | 13 +++++
net/bluetooth/sco.c | 13 +++++
5 files changed, 133 insertions(+)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index e42bb8e03c09..1576353a2773 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_PHY 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
__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 89ecf0a80aa1..dcc0dc6e2624 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1477,6 +1477,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_phy(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..9ff2611b272f 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1725,3 +1725,91 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle)
return hchan;
}
+
+u32 hci_conn_get_phy(struct hci_conn *conn)
+{
+ u32 phys = 0;
+
+ hci_dev_lock(conn->hdev);
+
+ switch (conn->type) {
+ case SCO_LINK:
+ phys |= BT_PHY_BR_1M_1SLOT;
+
+ break;
+
+ case ACL_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 ESCO_LINK:
+ phys |= BT_PHY_BR_1M_1SLOT;
+
+ if (!(conn->pkt_type & (ESCO_EV4 | ESCO_EV5)))
+ phys |= BT_PHY_BR_1M_3SLOT;
+
+ if (!(conn->pkt_type & ESCO_2EV3))
+ phys |= BT_PHY_EDR_2M_1SLOT;
+
+ if (!(conn->pkt_type & ESCO_2EV5))
+ phys |= BT_PHY_EDR_2M_3SLOT;
+
+ if (!(conn->pkt_type & ESCO_3EV3))
+ phys |= BT_PHY_EDR_3M_1SLOT;
+
+ if (!(conn->pkt_type & ESCO_3EV5))
+ phys |= BT_PHY_EDR_3M_3SLOT;
+
+ 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 390a9afab647..3df4a7cf85a3 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_PHY:
+ if (sk->sk_state == BT_CONNECTED) {
+ err = -EINVAL;
+ break;
+ }
+
+ phys = hci_conn_get_phy(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..95fdfa4b9b62 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_PHY:
+ if (sk->sk_state == BT_CONNECTED) {
+ err = -EINVAL;
+ break;
+ }
+
+ phys = hci_conn_get_phy(sco_pi(sk)->conn->hcon);
+
+ if (put_user(phys, (u32 __user *) optval))
+ err = -EFAULT;
+ break;
+
default:
err = -ENOPROTOOPT;
break;
--
2.21.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Bluetooth: Add BT_PHY socket option
2020-02-07 19:00 [PATCH] Bluetooth: Add BT_PHY socket option Luiz Augusto von Dentz
@ 2020-02-08 8:32 ` Marcel Holtmann
2020-02-10 21:13 ` Luiz Augusto von Dentz
0 siblings, 1 reply; 5+ messages in thread
From: Marcel Holtmann @ 2020-02-08 8:32 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hi Luiz,
> This adds BT_PHY socket option (read-only) 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 | 88 +++++++++++++++++++++++++++++++
> net/bluetooth/l2cap_sock.c | 13 +++++
> net/bluetooth/sco.c | 13 +++++
> 5 files changed, 133 insertions(+)
>
> diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
> index e42bb8e03c09..1576353a2773 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_PHY 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
>
> __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 89ecf0a80aa1..dcc0dc6e2624 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -1477,6 +1477,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_phy(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..9ff2611b272f 100644
> --- a/net/bluetooth/hci_conn.c
> +++ b/net/bluetooth/hci_conn.c
> @@ -1725,3 +1725,91 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle)
>
> return hchan;
> }
> +
> +u32 hci_conn_get_phy(struct hci_conn *conn)
> +{
> + u32 phys = 0;
> +
> + hci_dev_lock(conn->hdev);
> +
> + switch (conn->type) {
> + case SCO_LINK:
> + phys |= BT_PHY_BR_1M_1SLOT;
> +
> + break;
something is missing here. The SCO links can also be 3 and 5 slots.
> +
> + case ACL_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 ESCO_LINK:
> + phys |= BT_PHY_BR_1M_1SLOT;
> +
> + if (!(conn->pkt_type & (ESCO_EV4 | ESCO_EV5)))
> + phys |= BT_PHY_BR_1M_3SLOT;
> +
> + if (!(conn->pkt_type & ESCO_2EV3))
> + phys |= BT_PHY_EDR_2M_1SLOT;
> +
> + if (!(conn->pkt_type & ESCO_2EV5))
> + phys |= BT_PHY_EDR_2M_3SLOT;
> +
> + if (!(conn->pkt_type & ESCO_3EV3))
> + phys |= BT_PHY_EDR_3M_1SLOT;
> +
> + if (!(conn->pkt_type & ESCO_3EV5))
> + phys |= BT_PHY_EDR_3M_3SLOT;
> +
> + 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 390a9afab647..3df4a7cf85a3 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_PHY:
> + if (sk->sk_state == BT_CONNECTED) {
> + err = -EINVAL;
> + break;
> + }
> +
> + phys = hci_conn_get_phy(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..95fdfa4b9b62 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_PHY:
> + if (sk->sk_state == BT_CONNECTED) {
> + err = -EINVAL;
> + break;
> + }
> +
> + phys = hci_conn_get_phy(sco_pi(sk)->conn->hcon);
> +
> + if (put_user(phys, (u32 __user *) optval))
> + err = -EFAULT;
> + break;
> +
> default:
> err = -ENOPROTOOPT;
> break;
Regards
Marcel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Bluetooth: Add BT_PHY socket option
2020-02-08 8:32 ` Marcel Holtmann
@ 2020-02-10 21:13 ` Luiz Augusto von Dentz
2020-02-10 21:26 ` Luiz Augusto von Dentz
0 siblings, 1 reply; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2020-02-10 21:13 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
Hi Marcel,
On Sat, Feb 8, 2020 at 12:32 AM Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Luiz,
>
> > This adds BT_PHY socket option (read-only) 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 | 88 +++++++++++++++++++++++++++++++
> > net/bluetooth/l2cap_sock.c | 13 +++++
> > net/bluetooth/sco.c | 13 +++++
> > 5 files changed, 133 insertions(+)
> >
> > diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
> > index e42bb8e03c09..1576353a2773 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_PHY 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
> >
> > __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 89ecf0a80aa1..dcc0dc6e2624 100644
> > --- a/include/net/bluetooth/hci_core.h
> > +++ b/include/net/bluetooth/hci_core.h
> > @@ -1477,6 +1477,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_phy(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..9ff2611b272f 100644
> > --- a/net/bluetooth/hci_conn.c
> > +++ b/net/bluetooth/hci_conn.c
> > @@ -1725,3 +1725,91 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle)
> >
> > return hchan;
> > }
> > +
> > +u32 hci_conn_get_phy(struct hci_conn *conn)
> > +{
> > + u32 phys = 0;
> > +
> > + hci_dev_lock(conn->hdev);
> > +
> > + switch (conn->type) {
> > + case SCO_LINK:
> > + phys |= BT_PHY_BR_1M_1SLOT;
> > +
> > + break;
>
> something is missing here. The SCO links can also be 3 and 5 slots.
I couldn't find any information regarding the slot for HV1, HV2, HV3
and DV so I assume they were all using 1 slot.
> > +
> > + case ACL_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 ESCO_LINK:
> > + phys |= BT_PHY_BR_1M_1SLOT;
> > +
> > + if (!(conn->pkt_type & (ESCO_EV4 | ESCO_EV5)))
> > + phys |= BT_PHY_BR_1M_3SLOT;
> > +
> > + if (!(conn->pkt_type & ESCO_2EV3))
> > + phys |= BT_PHY_EDR_2M_1SLOT;
> > +
> > + if (!(conn->pkt_type & ESCO_2EV5))
> > + phys |= BT_PHY_EDR_2M_3SLOT;
> > +
> > + if (!(conn->pkt_type & ESCO_3EV3))
> > + phys |= BT_PHY_EDR_3M_1SLOT;
> > +
> > + if (!(conn->pkt_type & ESCO_3EV5))
> > + phys |= BT_PHY_EDR_3M_3SLOT;
> > +
> > + 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 390a9afab647..3df4a7cf85a3 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_PHY:
> > + if (sk->sk_state == BT_CONNECTED) {
> > + err = -EINVAL;
> > + break;
> > + }
> > +
> > + phys = hci_conn_get_phy(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..95fdfa4b9b62 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_PHY:
> > + if (sk->sk_state == BT_CONNECTED) {
> > + err = -EINVAL;
> > + break;
> > + }
> > +
> > + phys = hci_conn_get_phy(sco_pi(sk)->conn->hcon);
> > +
> > + if (put_user(phys, (u32 __user *) optval))
> > + err = -EFAULT;
> > + break;
> > +
> > default:
> > err = -ENOPROTOOPT;
> > break;
>
> Regards
>
> Marcel
>
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Bluetooth: Add BT_PHY socket option
2020-02-10 21:13 ` Luiz Augusto von Dentz
@ 2020-02-10 21:26 ` Luiz Augusto von Dentz
2020-02-14 7:52 ` Marcel Holtmann
0 siblings, 1 reply; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2020-02-10 21:26 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
Hi Marcel,
On Mon, Feb 10, 2020 at 1:13 PM Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> Hi Marcel,
>
> On Sat, Feb 8, 2020 at 12:32 AM Marcel Holtmann <marcel@holtmann.org> wrote:
> >
> > Hi Luiz,
> >
> > > This adds BT_PHY socket option (read-only) 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 | 88 +++++++++++++++++++++++++++++++
> > > net/bluetooth/l2cap_sock.c | 13 +++++
> > > net/bluetooth/sco.c | 13 +++++
> > > 5 files changed, 133 insertions(+)
> > >
> > > diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
> > > index e42bb8e03c09..1576353a2773 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_PHY 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
> > >
> > > __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 89ecf0a80aa1..dcc0dc6e2624 100644
> > > --- a/include/net/bluetooth/hci_core.h
> > > +++ b/include/net/bluetooth/hci_core.h
> > > @@ -1477,6 +1477,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_phy(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..9ff2611b272f 100644
> > > --- a/net/bluetooth/hci_conn.c
> > > +++ b/net/bluetooth/hci_conn.c
> > > @@ -1725,3 +1725,91 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle)
> > >
> > > return hchan;
> > > }
> > > +
> > > +u32 hci_conn_get_phy(struct hci_conn *conn)
> > > +{
> > > + u32 phys = 0;
> > > +
> > > + hci_dev_lock(conn->hdev);
> > > +
> > > + switch (conn->type) {
> > > + case SCO_LINK:
> > > + phys |= BT_PHY_BR_1M_1SLOT;
> > > +
> > > + break;
> >
> > something is missing here. The SCO links can also be 3 and 5 slots.
>
> I couldn't find any information regarding the slot for HV1, HV2, HV3
> and DV so I assume they were all using 1 slot.
It is actually 1 slot, see:
BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 2, Part B
page 471
Table 6.2: Packets defined for synchronous, asynchronous, and CSB
logical transport types
>
> > > +
> > > + case ACL_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 ESCO_LINK:
> > > + phys |= BT_PHY_BR_1M_1SLOT;
> > > +
> > > + if (!(conn->pkt_type & (ESCO_EV4 | ESCO_EV5)))
> > > + phys |= BT_PHY_BR_1M_3SLOT;
> > > +
> > > + if (!(conn->pkt_type & ESCO_2EV3))
> > > + phys |= BT_PHY_EDR_2M_1SLOT;
> > > +
> > > + if (!(conn->pkt_type & ESCO_2EV5))
> > > + phys |= BT_PHY_EDR_2M_3SLOT;
> > > +
> > > + if (!(conn->pkt_type & ESCO_3EV3))
> > > + phys |= BT_PHY_EDR_3M_1SLOT;
> > > +
> > > + if (!(conn->pkt_type & ESCO_3EV5))
> > > + phys |= BT_PHY_EDR_3M_3SLOT;
> > > +
> > > + 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 390a9afab647..3df4a7cf85a3 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_PHY:
> > > + if (sk->sk_state == BT_CONNECTED) {
> > > + err = -EINVAL;
> > > + break;
> > > + }
> > > +
> > > + phys = hci_conn_get_phy(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..95fdfa4b9b62 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_PHY:
> > > + if (sk->sk_state == BT_CONNECTED) {
> > > + err = -EINVAL;
> > > + break;
> > > + }
> > > +
> > > + phys = hci_conn_get_phy(sco_pi(sk)->conn->hcon);
> > > +
> > > + if (put_user(phys, (u32 __user *) optval))
> > > + err = -EFAULT;
> > > + break;
> > > +
> > > default:
> > > err = -ENOPROTOOPT;
> > > break;
> >
> > Regards
> >
> > Marcel
> >
>
>
> --
> Luiz Augusto von Dentz
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Bluetooth: Add BT_PHY socket option
2020-02-10 21:26 ` Luiz Augusto von Dentz
@ 2020-02-14 7:52 ` Marcel Holtmann
0 siblings, 0 replies; 5+ messages in thread
From: Marcel Holtmann @ 2020-02-14 7:52 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hi Luiz,
>>>> This adds BT_PHY socket option (read-only) 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 | 88 +++++++++++++++++++++++++++++++
>>>> net/bluetooth/l2cap_sock.c | 13 +++++
>>>> net/bluetooth/sco.c | 13 +++++
>>>> 5 files changed, 133 insertions(+)
>>>>
>>>> diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
>>>> index e42bb8e03c09..1576353a2773 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_PHY 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
>>>>
>>>> __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 89ecf0a80aa1..dcc0dc6e2624 100644
>>>> --- a/include/net/bluetooth/hci_core.h
>>>> +++ b/include/net/bluetooth/hci_core.h
>>>> @@ -1477,6 +1477,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_phy(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..9ff2611b272f 100644
>>>> --- a/net/bluetooth/hci_conn.c
>>>> +++ b/net/bluetooth/hci_conn.c
>>>> @@ -1725,3 +1725,91 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle)
>>>>
>>>> return hchan;
>>>> }
>>>> +
>>>> +u32 hci_conn_get_phy(struct hci_conn *conn)
>>>> +{
>>>> + u32 phys = 0;
>>>> +
>>>> + hci_dev_lock(conn->hdev);
>>>> +
>>>> + switch (conn->type) {
>>>> + case SCO_LINK:
>>>> + phys |= BT_PHY_BR_1M_1SLOT;
>>>> +
>>>> + break;
>>>
>>> something is missing here. The SCO links can also be 3 and 5 slots.
>>
>> I couldn't find any information regarding the slot for HV1, HV2, HV3
>> and DV so I assume they were all using 1 slot.
>
> It is actually 1 slot, see:
>
> BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 2, Part B
> page 471
> Table 6.2: Packets defined for synchronous, asynchronous, and CSB
> logical transport types
good call. I even managed to expunge that from my brain after 20 years of Bluetooth 1.1 spec ;)
Regards
Marcel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-02-14 7:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-07 19:00 [PATCH] Bluetooth: Add BT_PHY socket option Luiz Augusto von Dentz
2020-02-08 8:32 ` Marcel Holtmann
2020-02-10 21:13 ` Luiz Augusto von Dentz
2020-02-10 21:26 ` Luiz Augusto von Dentz
2020-02-14 7:52 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).