Skip to content

Commit eab2404

Browse files
Vudentzholtmann
authored andcommitted
Bluetooth: Add BT_PHY socket option
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> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent cee5f20 commit eab2404

5 files changed

Lines changed: 152 additions & 0 deletions

File tree

‎include/net/bluetooth/bluetooth.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ struct bt_voice {
121121

122122
#define BT_SNDMTU 12
123123
#define BT_RCVMTU 13
124+
#define BT_PHY 14
125+
126+
#define BT_PHY_BR_1M_1SLOT 0x00000001
127+
#define BT_PHY_BR_1M_3SLOT 0x00000002
128+
#define BT_PHY_BR_1M_5SLOT 0x00000004
129+
#define BT_PHY_EDR_2M_1SLOT 0x00000008
130+
#define BT_PHY_EDR_2M_3SLOT 0x00000010
131+
#define BT_PHY_EDR_2M_5SLOT 0x00000020
132+
#define BT_PHY_EDR_3M_1SLOT 0x00000040
133+
#define BT_PHY_EDR_3M_3SLOT 0x00000080
134+
#define BT_PHY_EDR_3M_5SLOT 0x00000100
135+
#define BT_PHY_LE_1M_TX 0x00000200
136+
#define BT_PHY_LE_1M_RX 0x00000400
137+
#define BT_PHY_LE_2M_TX 0x00000800
138+
#define BT_PHY_LE_2M_RX 0x00001000
139+
#define BT_PHY_LE_CODED_TX 0x00002000
140+
#define BT_PHY_LE_CODED_RX 0x00004000
124141

125142
__printf(1, 2)
126143
void bt_info(const char *fmt, ...);

‎include/net/bluetooth/hci_core.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,8 @@ void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
14771477
struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
14781478
const void *param, u32 timeout);
14791479

1480+
u32 hci_conn_get_phy(struct hci_conn *conn);
1481+
14801482
/* ----- HCI Sockets ----- */
14811483
void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
14821484
void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,

‎net/bluetooth/hci_conn.c‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,3 +1725,110 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle)
17251725

17261726
return hchan;
17271727
}
1728+
1729+
u32 hci_conn_get_phy(struct hci_conn *conn)
1730+
{
1731+
u32 phys = 0;
1732+
1733+
hci_dev_lock(conn->hdev);
1734+
1735+
/* BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 2, Part B page 471:
1736+
* Table 6.2: Packets defined for synchronous, asynchronous, and
1737+
* CSB logical transport types.
1738+
*/
1739+
switch (conn->type) {
1740+
case SCO_LINK:
1741+
/* SCO logical transport (1 Mb/s):
1742+
* HV1, HV2, HV3 and DV.
1743+
*/
1744+
phys |= BT_PHY_BR_1M_1SLOT;
1745+
1746+
break;
1747+
1748+
case ACL_LINK:
1749+
/* ACL logical transport (1 Mb/s) ptt=0:
1750+
* DH1, DM3, DH3, DM5 and DH5.
1751+
*/
1752+
phys |= BT_PHY_BR_1M_1SLOT;
1753+
1754+
if (conn->pkt_type & (HCI_DM3 | HCI_DH3))
1755+
phys |= BT_PHY_BR_1M_3SLOT;
1756+
1757+
if (conn->pkt_type & (HCI_DM5 | HCI_DH5))
1758+
phys |= BT_PHY_BR_1M_5SLOT;
1759+
1760+
/* ACL logical transport (2 Mb/s) ptt=1:
1761+
* 2-DH1, 2-DH3 and 2-DH5.
1762+
*/
1763+
if (!(conn->pkt_type & HCI_2DH1))
1764+
phys |= BT_PHY_EDR_2M_1SLOT;
1765+
1766+
if (!(conn->pkt_type & HCI_2DH3))
1767+
phys |= BT_PHY_EDR_2M_3SLOT;
1768+
1769+
if (!(conn->pkt_type & HCI_2DH5))
1770+
phys |= BT_PHY_EDR_2M_5SLOT;
1771+
1772+
/* ACL logical transport (3 Mb/s) ptt=1:
1773+
* 3-DH1, 3-DH3 and 3-DH5.
1774+
*/
1775+
if (!(conn->pkt_type & HCI_3DH1))
1776+
phys |= BT_PHY_EDR_3M_1SLOT;
1777+
1778+
if (!(conn->pkt_type & HCI_3DH3))
1779+
phys |= BT_PHY_EDR_3M_3SLOT;
1780+
1781+
if (!(conn->pkt_type & HCI_3DH5))
1782+
phys |= BT_PHY_EDR_3M_5SLOT;
1783+
1784+
break;
1785+
1786+
case ESCO_LINK:
1787+
/* eSCO logical transport (1 Mb/s): EV3, EV4 and EV5 */
1788+
phys |= BT_PHY_BR_1M_1SLOT;
1789+
1790+
if (!(conn->pkt_type & (ESCO_EV4 | ESCO_EV5)))
1791+
phys |= BT_PHY_BR_1M_3SLOT;
1792+
1793+
/* eSCO logical transport (2 Mb/s): 2-EV3, 2-EV5 */
1794+
if (!(conn->pkt_type & ESCO_2EV3))
1795+
phys |= BT_PHY_EDR_2M_1SLOT;
1796+
1797+
if (!(conn->pkt_type & ESCO_2EV5))
1798+
phys |= BT_PHY_EDR_2M_3SLOT;
1799+
1800+
/* eSCO logical transport (3 Mb/s): 3-EV3, 3-EV5 */
1801+
if (!(conn->pkt_type & ESCO_3EV3))
1802+
phys |= BT_PHY_EDR_3M_1SLOT;
1803+
1804+
if (!(conn->pkt_type & ESCO_3EV5))
1805+
phys |= BT_PHY_EDR_3M_3SLOT;
1806+
1807+
break;
1808+
1809+
case LE_LINK:
1810+
if (conn->le_tx_phy & HCI_LE_SET_PHY_1M)
1811+
phys |= BT_PHY_LE_1M_TX;
1812+
1813+
if (conn->le_rx_phy & HCI_LE_SET_PHY_1M)
1814+
phys |= BT_PHY_LE_1M_RX;
1815+
1816+
if (conn->le_tx_phy & HCI_LE_SET_PHY_2M)
1817+
phys |= BT_PHY_LE_2M_TX;
1818+
1819+
if (conn->le_rx_phy & HCI_LE_SET_PHY_2M)
1820+
phys |= BT_PHY_LE_2M_RX;
1821+
1822+
if (conn->le_tx_phy & HCI_LE_SET_PHY_CODED)
1823+
phys |= BT_PHY_LE_CODED_TX;
1824+
1825+
if (conn->le_rx_phy & HCI_LE_SET_PHY_CODED)
1826+
phys |= BT_PHY_LE_CODED_RX;
1827+
1828+
break;
1829+
}
1830+
1831+
hci_dev_unlock(conn->hdev);
1832+
1833+
return phys;
1834+
}

‎net/bluetooth/l2cap_sock.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,
499499
struct l2cap_chan *chan = l2cap_pi(sk)->chan;
500500
struct bt_security sec;
501501
struct bt_power pwr;
502+
u32 phys;
502503
int len, err = 0;
503504

504505
BT_DBG("sk %p", sk);
@@ -603,6 +604,18 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,
603604
err = -EFAULT;
604605
break;
605606

607+
case BT_PHY:
608+
if (sk->sk_state == BT_CONNECTED) {
609+
err = -ENOTCONN;
610+
break;
611+
}
612+
613+
phys = hci_conn_get_phy(chan->conn->hcon);
614+
615+
if (put_user(phys, (u32 __user *) optval))
616+
err = -EFAULT;
617+
break;
618+
606619
default:
607620
err = -ENOPROTOOPT;
608621
break;

‎net/bluetooth/sco.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname,
922922
struct sock *sk = sock->sk;
923923
int len, err = 0;
924924
struct bt_voice voice;
925+
u32 phys;
925926

926927
BT_DBG("sk %p", sk);
927928

@@ -956,6 +957,18 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname,
956957

957958
break;
958959

960+
case BT_PHY:
961+
if (sk->sk_state == BT_CONNECTED) {
962+
err = -ENOTCONN;
963+
break;
964+
}
965+
966+
phys = hci_conn_get_phy(sco_pi(sk)->conn->hcon);
967+
968+
if (put_user(phys, (u32 __user *) optval))
969+
err = -EFAULT;
970+
break;
971+
959972
default:
960973
err = -ENOPROTOOPT;
961974
break;

0 commit comments

Comments
 (0)