Bluetooth: L2CAP: Add support for setting BT_PHY
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH v2 1/1 Bluetooth: L2CAP: Add support for setting BT_PHY
From: Luiz Augusto von Dentz <[email protected]>
This enables client to use setsockopt(BT_PHY) to set the connection packet type/PHY:
Example setting BT_PHY_BR_1M_1SLOT:
< HCI Command: Change Conne.. (0x01|0x000f) plen 4
Handle: 1 Address: 00:AA:01:01:00:00 (Intel Corporation) Packet type: 0x331e
2-DH1 may not be used
3-DH1 may not be used
DM1 may be used
DH1 may be used
2-DH3 may not be used
3-DH3 may not be used
2-DH5 may not be used
3-DH5 may not be used
Quoted 1 line
HCI Event: Command Status (
0x0f) plen 4
Change Connection Packet Type (0x01|0x000f) ncmd 1
Status: Success (0x00)Quoted 1 line
HCI Event: Connection Packet Typ.. (
0x1d) plen 5
Status: Success (0x00)
Handle: 1 Address: 00:AA:01:01:00:00 (Intel Corporation) Packet type: 0x331e
2-DH1 may not be used
3-DH1 may not be used
DM1 may be used
DH1 may be used
2-DH3 may not be used
3-DH3 may not be used
2-DH5 may not be used
Example setting BT_PHY_LE_1M_TX and BT_PHY_LE_1M_RX:
< HCI Command: LE Set PHY (0x08|0x0032) plen 7
Handle: 1 Address: 00:AA:01:01:00:00 (Intel Corporation)
All PHYs preference: 0x00
TX PHYs preference: 0x01
LE 1M
RX PHYs preference: 0x01
LE 1M
PHY options preference: Reserved (0x0000)Quoted 1 line
HCI Event: Command Status (
0x0f) plen 4
LE Set PHY (0x08|0x0032) ncmd 1
Status: Success (0x00)Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 6
LE PHY Update Complete (0x0c)
Status: Success (0x00)
Handle: 1 Address: 00:AA:01:01:00:00 (Intel Corporation)
TX PHY: LE 1M (0x01)
RX PHY: LE 1M (0x01)--- include/net/bluetooth/bluetooth.h | 39 ++++++----- include/net/bluetooth/hci.h | 9 +++ include/net/bluetooth/hci_core.h | 1 + include/net/bluetooth/hci_sync.h | 3 + net/bluetooth/hci_conn.c | 105 ++++++++++++++++++++++++++++++ net/bluetooth/hci_event.c | 26 ++++++++ net/bluetooth/hci_sync.c | 72 ++++++++++++++++++++ net/bluetooth/l2cap_sock.c | 20 +++++- 8 files changed, 259 insertions(+), 16 deletions(-)
include/net/bluetooth/bluetooth.h +24 -15
@@ -130,21 +130,30 @@ struct bt_voice {#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 +#define BT_PHY_BR_1M_1SLOT BIT(0) +#define BT_PHY_BR_1M_3SLOT BIT(1) +#define BT_PHY_BR_1M_5SLOT BIT(2) +#define BT_PHY_EDR_2M_1SLOT BIT(3) +#define BT_PHY_EDR_2M_3SLOT BIT(4) +#define BT_PHY_EDR_2M_5SLOT BIT(5) +#define BT_PHY_EDR_3M_1SLOT BIT(6) +#define BT_PHY_EDR_3M_3SLOT BIT(7) +#define BT_PHY_EDR_3M_5SLOT BIT(8) +#define BT_PHY_LE_1M_TX BIT(9) +#define BT_PHY_LE_1M_RX BIT(10) +#define BT_PHY_LE_2M_TX BIT(11) +#define BT_PHY_LE_2M_RX BIT(12) +#define BT_PHY_LE_CODED_TX BIT(13) +#define BT_PHY_LE_CODED_RX BIT(14) + +#define BT_PHY_BREDR_MASK (BT_PHY_BR_1M_1SLOT | BT_PHY_BR_1M_3SLOT | \ + BT_PHY_BR_1M_5SLOT | BT_PHY_EDR_2M_1SLOT | \ + BT_PHY_EDR_2M_3SLOT | BT_PHY_EDR_2M_5SLOT | \ + BT_PHY_EDR_3M_1SLOT | BT_PHY_EDR_3M_3SLOT | \ + BT_PHY_EDR_3M_5SLOT) +#define BT_PHY_LE_MASK (BT_PHY_LE_1M_TX | BT_PHY_LE_1M_RX | \ + BT_PHY_LE_2M_TX | BT_PHY_LE_2M_RX | \ + BT_PHY_LE_CODED_TX | BT_PHY_LE_CODED_RX)#define BT_MODE 15
include/net/bluetooth/hci.h +9 -0
@@ -1885,6 +1885,15 @@ struct hci_cp_le_set_default_phy {#define HCI_LE_SET_PHY_2M 0x02#define HCI_LE_SET_PHY_CODED 0x04 +#define HCI_OP_LE_SET_PHY 0x2032 +struct hci_cp_le_set_phy { +__le16 handle; +__u8 all_phys; +__u8 tx_phys; +__u8 rx_phys; +__le16 phy_opts; +} __packed; +#define HCI_OP_LE_SET_EXT_SCAN_PARAMS 0x2041struct hci_cp_le_set_ext_scan_params {__u8 own_addr_type;
include/net/bluetooth/hci_core.h +1 -0
@@ -2342,6 +2342,7 @@ void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);void *hci_recv_event_data (struct hci_dev *hdev,__u8 event);u32 hci_conn_get_phy (struct hci_conn *conn); +int hci_conn_set_phy (struct hci_conn *conn,u32 phys);/* ----- HCI Sockets ----- */ void hci_send_to_sock (struct hci_dev *hdev,struct sk_buff *skb);
include/net/bluetooth/hci_sync.h +3 -0
@@ -191,3 +191,6 @@ int hci_connect_big_sync(struct hci_dev *hdev, struct hci_conn *conn);int hci_past_sync (struct hci_conn *conn,struct hci_conn *le);int hci_le_read_remote_features (struct hci_conn *conn); + +int hci_acl_change_pkt_type (struct hci_conn *conn,u16 pkt_type); +int hci_le_set_phy (struct hci_conn *conn,u8 tx_phys,u8 rx_phys);
net/bluetooth/hci_conn.c +105 -0
111 lines not on this page · raw message
net/bluetooth/hci_event.c +26 -0
@@ -2869,6 +2869,31 @@ static void hci_cs_le_ext_create_conn(struct hci_dev *hdev, u8 status)hci_dev_unlock (hdev); } +static void hci_cs_le_set_phy (struct hci_dev *hdev,u8 status) +{ +struct hci_cp_le_set_phy *cp; +struct hci_conn *conn; + +bt_dev_dbg (hdev,"status 0x%2.2x" , status); + +if (status) +return ; + + cp =hci_sent_cmd_data (hdev,HCI_OP_LE_SET_PHY ); +if (!cp) +return ; + +hci_dev_lock (hdev); + + conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (cp->handle)); +if (conn) { + conn->le_tx_def_phys = cp->tx_phys; + conn->le_rx_def_phys = cp->rx_phys; + } + +hci_dev_unlock (hdev); +} +static void hci_cs_le_read_remote_features (struct hci_dev *hdev,u8 status) {struct hci_cp_le_read_remote_features *cp;
@@ -4359,6 +4384,7 @@ static const struct hci_cs {HCI_CS (HCI_OP_LE_CREATE_CONN , hci_cs_le_create_conn),HCI_CS (HCI_OP_LE_READ_REMOTE_FEATURES , hci_cs_le_read_remote_features),HCI_CS (HCI_OP_LE_START_ENC , hci_cs_le_start_enc), +HCI_CS (HCI_OP_LE_SET_PHY , hci_cs_le_set_phy),HCI_CS (HCI_OP_LE_EXT_CREATE_CONN , hci_cs_le_ext_create_conn),HCI_CS (HCI_OP_LE_CREATE_CIS , hci_cs_le_create_cis), HCI_CS(HCI_OP_LE_CREATE_BIG, hci_cs_le_create_big),
net/bluetooth/hci_sync.c +72 -0
75 lines not on this page · raw message
net/bluetooth/l2cap_sock.c +19 -1
@@ -885,7 +885,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,struct bt_power pwr;struct l2cap_conn *conn;int err =0 ; -u32 opt; +u32 opt, phys;u16 mtu;u8 mode;
@@ -1059,6 +1059,24 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,break ; +case BT_PHY : +if (sk->sk_state !=BT_CONNECTED ) { + err = -ENOTCONN ; +break ; + } + + err =copy_safe_from_sockptr (&phys,sizeof (phys), optval, + optlen); +if (err) +break ; + +if (!chan->conn) +break ; + + conn = chan->conn; + err =hci_conn_set_phy (conn->hcon, phys); +break ; +case BT_MODE :if (!enable_ecred) { err = -ENOPROTOOPT ;
Signature · 1 line
2.52.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1034736
---Test result---
Test Summary:
CheckPatch PENDING 0.51 seconds GitLint PENDING 0.27 seconds SubjectPrefix PASS 0.21 seconds BuildKernel PASS 26.24 seconds CheckAllWarning PASS 28.93 seconds CheckSparse WARNING 32.43 seconds BuildKernel32 PASS 25.24 seconds TestRunnerSetup PASS 565.72 seconds TestRunner_l2cap-tester PASS 26.22 seconds TestRunner_iso-tester FAIL 49.21 seconds TestRunner_bnep-tester PASS 6.45 seconds TestRunner_mgmt-tester FAIL 127.81 seconds TestRunner_rfcomm-tester PASS 9.77 seconds TestRunner_sco-tester FAIL 15.04 seconds TestRunner_ioctl-tester PASS 10.54 seconds TestRunner_mesh-tester FAIL 12.69 seconds TestRunner_smp-tester PASS 8.92 seconds TestRunner_userchan-tester PASS 7.00 seconds IncrementalBuild PENDING 0.71 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
Output:
BUG: KASAN: slab-use-after-free in le_read_features_complete+0x7e/0x2b0
Total: 141, Passed: 141 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4
Failed Test Cases
Read Exp Feature - Success Failed 0.107 seconds
##############################
Test: TestRunner_sco-tester - FAIL
Desc: Run sco-tester with test-runner
Output:
WARNING: possible circular locking dependency detected
BUG: sleeping function called from invalid context at net/core/sock.c:3782
Total: 30, Passed: 30 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0
Failed Test Cases
Mesh - Send cancel - 1 Timed out 2.654 seconds Mesh - Send cancel - 2 Timed out 2.001 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:
---
Regards,
Linux Bluetooth
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 8 lines · On Thu, 18 Dec 2025 14:21:59 -0500 you wrote:
From: Luiz Augusto von Dentz <[email protected]>
This enables client to use
setsockopt(BT_PHY)to set the connection packet type/PHY:Example setting
BT_PHY_BR_1M_1SLOT:[...]
Here is the summary with links:
- [v2] Bluetooth: L2CAP: Add support for setting BT_PHY
https://git.kernel.org/bluetooth/bluetooth-next/c/98246938a0e6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html