Skip to contentSkip to conversation

Bluetooth: HCI: Add support for LE PHY Update Complete event

RFC In review Luiz Augusto von Dentz 3 participants 7 messages Jan 2, 2020 – Jan 3, 2020

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

RFC 1/2 Bluetooth: HCI: Add support for LE PHY Update Complete event

From: Luiz Augusto von Dentz <[email protected]>

This handles LE PHY Update Complete event and store both tx_phy and rx_phy into hci_conn.

---
 include/net/bluetooth/hci.h      |  8 ++++++++
 include/net/bluetooth/hci_core.h |  2 ++
 net/bluetooth/hci_event.c        | 27 +++++++++++++++++++++++++++
 3 files changed, 37 insertions(+)
include/net/bluetooth/hci.h +8 -0
index 5bc1e30dedde..07b6ecedc6ce 100644
@@ -2186,6 +2186,14 @@ struct hci_ev_le_direct_adv_info {
 	__s8	 rssi;
 } __packed;
 
+#define HCI_EV_LE_PHY_UPDATE_COMPLETE	0x0c
+struct hci_ev_le_phy_update_complete {
+	__u8  status;
+	__u16 handle;
+	__u8  tx_phy;
+	__u8  rx_phy;
+} __packed;
+
 #define HCI_EV_LE_EXT_ADV_REPORT    0x0d
 struct hci_ev_le_ext_adv_report {
 	__le16 	 evt_type;
include/net/bluetooth/hci_core.h +2 -0
index b689aceb636b..faebe3859931 100644
@@ -493,6 +493,8 @@ struct hci_conn {
 	__u16		le_supv_timeout;
 	__u8		le_adv_data[HCI_MAX_AD_LENGTH];
 	__u8		le_adv_data_len;
+	__u8		le_tx_phy;
+	__u8		le_rx_phy;
 	__s8		rssi;
 	__s8		tx_power;
 	__s8		max_tx_power;
net/bluetooth/hci_event.c +27 -0
index 1941f120a376..6ddc4a74a5e4 100644
@@ -5718,6 +5718,29 @@ static void hci_le_direct_adv_report_evt(struct hci_dev *hdev,
 	hci_dev_unlock(hdev);
 }
 
+static void hci_le_phy_update_evt(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	struct hci_ev_le_phy_update_complete *ev = (void *) skb->data;
+	struct hci_conn *conn;
+
+	BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
+
+	if (!ev->status)
+		return;
+
+	hci_dev_lock(hdev);
+
+	conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
+	if (!conn)
+		goto unlock;
+
+	conn->le_tx_phy = ev->tx_phy;
+	conn->le_rx_phy = ev->rx_phy;
+
+unlock:
+	hci_dev_unlock(hdev);
+}
+
 static void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct hci_ev_le_meta *le_ev = (void *) skb->data;
@@ -5753,6 +5776,10 @@ static void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		hci_le_direct_adv_report_evt(hdev, skb);
 		break;
 
+	case HCI_EV_LE_PHY_UPDATE_COMPLETE:
+		hci_le_phy_update_evt(hdev, skb);
+		break;
+
 	case HCI_EV_LE_EXT_ADV_REPORT:
 		hci_le_ext_adv_report_evt(hdev, skb);
 		break;
Signature · 1 line
2.21.0
author maintainer
#1 lore raw

RFC 2/2 Bluetooth: Add BT_PHYS socket option

From: Luiz Augusto von Dentz <[email protected]>

This adds BT_PHYS socket option which can be used to read the PHYs in use by the underline connection.

---
 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(+)
include/net/bluetooth/bluetooth.h +17 -0
index e42bb8e03c09..69c0e7eb26d9 100644
@@ -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
 
 __printf(1, 2)
 void bt_info(const char *fmt, ...);
include/net/bluetooth/hci_core.h +2 -0
index faebe3859931..03cf3f0f22b9 100644
@@ -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,
net/bluetooth/hci_conn.c +64 -0

67 lines not on this page · raw message

net/bluetooth/l2cap_sock.c +13 -0
index a7be8b59b3c2..fb011c6c67be 100644
@@ -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;
net/bluetooth/sco.c +13 -0
index b91d6b440fdf..dcd297f2acc6 100644
@@ -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;
Signature · 1 line
2.21.0
author maintainer
#2 lore raw

Re: [RFC 2/2] Bluetooth: Add BT_PHYS socket option

Hi Pali,

Quoted 30 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds BT_PHYS socket option which can be used to read the PHYs in use by the underline connection.

---
 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(+)
include/net/bluetooth/bluetooth.h +7 -0
index e42bb8e03c09..69c0e7eb26d9 100644
@@ -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

include/net/bluetooth/bluetooth.h struct bt_voice { · line 140

Quoted 10 lines
include/net/bluetooth/bluetooth.h +10 -0
+#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.

Quoted 152 lines
include/net/bluetooth/bluetooth.h +0 -0
 __printf(1, 2)
 void bt_info(const char *fmt, ...);
include/net/bluetooth/hci_core.h +2 -0
index faebe3859931..03cf3f0f22b9 100644
@@ -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,
net/bluetooth/hci_conn.c +64 -0
index 87691404d0c6..386e6b0bd2ab 100644
@@ -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;
+}
net/bluetooth/l2cap_sock.c +13 -0
index a7be8b59b3c2..fb011c6c67be 100644
@@ -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;
net/bluetooth/sco.c +13 -1
index b91d6b440fdf..dcd297f2acc6 100644
@@ -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

Signature · 1 line
Luiz Augusto von Dentz
#3 lore raw

Re: [RFC 2/2] Bluetooth: Add BT_PHYS socket option

Quoted 41 lines · On Thursday 02 January 2020 09:36:06 Luiz Augusto von Dentz wrote:

Hi Pali,

Quoted 37 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds BT_PHYS socket option which can be used to read the PHYs in use by the underline connection.

---
 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(+)
include/net/bluetooth/bluetooth.h +14 -0
index e42bb8e03c09..69c0e7eb26d9 100644
@@ -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
Quoted 8 lines

include/net/bluetooth/bluetooth.h struct bt_voice { · line 140

Quoted 3 lines
include/net/bluetooth/bluetooth.h +3 -0
+#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?

Quoted 154 lines
Quoted 152 lines
include/net/bluetooth/bluetooth.h +0 -0
 __printf(1, 2)
 void bt_info(const char *fmt, ...);
include/net/bluetooth/hci_core.h +2 -0
index faebe3859931..03cf3f0f22b9 100644
@@ -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,
net/bluetooth/hci_conn.c +64 -0
index 87691404d0c6..386e6b0bd2ab 100644
@@ -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;
+}
net/bluetooth/l2cap_sock.c +13 -0
index a7be8b59b3c2..fb011c6c67be 100644
@@ -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;
net/bluetooth/sco.c +13 -1
index b91d6b440fdf..dcd297f2acc6 100644
@@ -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

Signature · 2 lines
Pali Rohár
[email protected]
author maintainer
#4 lore raw

Re: [RFC 2/2] Bluetooth: Add BT_PHYS socket option

Hi Pali.

Quoted 52 lines · Pali Rohár
Quoted 41 lines · On Thursday 02 January 2020 09:36:06 Luiz Augusto von Dentz wrote:

Hi Pali,

Quoted 37 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds BT_PHYS socket option which can be used to read the PHYs in use by the underline connection.

---
 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(+)
include/net/bluetooth/bluetooth.h +14 -0
index e42bb8e03c09..69c0e7eb26d9 100644
@@ -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
Quoted 8 lines

include/net/bluetooth/bluetooth.h struct bt_voice { · line 140

Quoted 3 lines
include/net/bluetooth/bluetooth.h +3 -0
+#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.

Quoted 4 lines

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.

Quoted 158 lines
Quoted 144 lines
Quoted 144 lines
include/net/bluetooth/bluetooth.h +0 -0
 __printf(1, 2)
 void bt_info(const char *fmt, ...);
include/net/bluetooth/hci_core.h +2 -0
index faebe3859931..03cf3f0f22b9 100644
@@ -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,
net/bluetooth/hci_conn.c +64 -0
index 87691404d0c6..386e6b0bd2ab 100644
@@ -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;
+}
net/bluetooth/l2cap_sock.c +13 -0
index a7be8b59b3c2..fb011c6c67be 100644
@@ -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;
net/bluetooth/sco.c +11 -0
index b91d6b440fdf..dcd297f2acc6 100644
@@ -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;
Quoted 10 lines
Quoted 8 lines
net/bluetooth/sco.c +2 -1
+               break;
+
        default:
                err = -ENOPROTOOPT;
                break;
--

2.21.0

--
Pali Rohár
[email protected]

Signature · 1 line
Luiz Augusto von Dentz
#5 lore raw

RE: [RFC 2/2] Bluetooth: Add BT_PHYS socket option

In reply to Luiz Augusto von Dentz
Quoted 15 lines
include/net/bluetooth/bluetooth.h +7 -0
index e42bb8e03c09..69c0e7eb26d9 100644
@@ -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

include/net/bluetooth/bluetooth.h struct bt_voice { · line 140

Quoted 10 lines
include/net/bluetooth/bluetooth.h +10 -0
+#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

My query about this is there is an option for LE Coded, but LE coded can have a data rate of 125Kbps or 500Kbps, is there no need to differentiate between the two rates in applications?
THIS MESSAGE, ANY ATTACHMENT(S), AND THE INFORMATION CONTAINED HEREIN MAY BE PROPRIETARY TO LAIRD CONNECTIVITY, INC. AND/OR ANOTHER PARTY, AND MAY FURTHER BE INTENDED TO BE KEPT CONFIDENTIAL. IF YOU ARE NOT THE INTENDED RECIPIENT, PLEASE DELETE THE EMAIL AND ANY ATTACHMENTS, AND IMMEDIATELY NOTIFY THE SENDER BY RETURN EMAIL. THIS MESSAGE AND ITS CONTENTS ARE THE PROPERTY OF LAIRD CONNECTIVITY, INC. AND MAY NOT BE REPRODUCED OR USED WITHOUT THE EXPRESS WRITTEN CONSENT OF LAIRD CONNECTIVITY, INC.

author maintainer
#6 lore raw

Re: [RFC 2/2] Bluetooth: Add BT_PHYS socket option

Hi Jamie,

Quoted 20 lines · Jamie Mccrae
Quoted 20 lines
include/net/bluetooth/bluetooth.h +11 -0
index e42bb8e03c09..69c0e7eb26d9 100644
@@ -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
Quoted 8 lines

include/net/bluetooth/bluetooth.h struct bt_voice { · line 140

Quoted 6 lines
include/net/bluetooth/bluetooth.h +6 -0
+#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

My query about this is there is an option for LE Coded, but LE coded can have a data rate of 125Kbps or 500Kbps, is there no need to differentiate between the two rates in applications?

I guess you referring to L=2 and L=8 payloads, those are unfortunately not exposed over HCI, they seem to be tied to LL power control and not with the PHY selection so Im not sure how we would be able to infer what payload is in use. Btw, I've the PHY bit fields to match what we use in the management socket,

Signature · 1 line
Luiz Augusto von Dentz