Bluetooth: L2CAP: Add support for setting BT_PHY
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH 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 | 106 ++++++++++++++++++++++++++++++ net/bluetooth/hci_event.c | 26 ++++++++ net/bluetooth/hci_sync.c | 72 ++++++++++++++++++++ net/bluetooth/l2cap_sock.c | 20 +++++- 8 files changed, 260 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
@@ -1883,6 +1883,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
@@ -2336,6 +2336,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 +106 -0
112 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=1034337
---Test result---
Test Summary:
CheckPatch PENDING 0.35 seconds GitLint PENDING 0.29 seconds SubjectPrefix PASS 0.09 seconds BuildKernel PASS 22.73 seconds CheckAllWarning WARNING 24.92 seconds CheckSparse WARNING 27.55 seconds BuildKernel32 PASS 22.19 seconds TestRunnerSetup PASS 494.47 seconds TestRunner_l2cap-tester PASS 24.70 seconds TestRunner_iso-tester PASS 72.82 seconds TestRunner_bnep-tester PASS 6.23 seconds TestRunner_mgmt-tester FAIL 110.71 seconds TestRunner_rfcomm-tester PASS 9.19 seconds TestRunner_sco-tester FAIL 14.11 seconds TestRunner_ioctl-tester PASS 9.85 seconds TestRunner_mesh-tester FAIL 11.47 seconds TestRunner_smp-tester PASS 8.45 seconds TestRunner_userchan-tester PASS 6.36 seconds IncrementalBuild PENDING 0.70 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: CheckAllWarning - WARNING
Desc: Run linux kernel with all warning enabled
Output:net/bluetooth/hci_conn.c: In function ‘hci_conn_set_phy’:net/bluetooth/hci_conn.c:3038:18: warning: unused variable ‘hdev’ [-Wunused-variable] 3038 | struct hci_dev *hdev = conn->hdev; | ^~~~
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:net/bluetooth/hci_conn.c: In function ‘hci_conn_set_phy’:net/bluetooth/hci_conn.c:3038:18: warning: unused variable ‘hdev’ [-Wunused-variable]net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
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.102 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.085 seconds Mesh - Send cancel - 2 Timed out 1.991 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:
---
Regards,
Linux Bluetooth
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Luiz,
kernel test robot noticed the following build warnings:
[auto build test WARNING on bluetooth-next/master]
[cannot apply to linus/master v6.16-rc1 next-20251219]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Luiz-Augusto-von-Dentz/Bluetooth-L2CAP-Add-support-for-setting-BT_PHY/20251218-045422 base: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master patch link: https://lore.kernel.org/r/20251217205221.285777-1-luiz.dentz%40gmail.com patch subject: [PATCH v1] Bluetooth: L2CAP: Add support for setting BT_PHY config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20251221/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251221/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
net/bluetooth/hci_conn.c: In function 'hci_conn_set_phy':
>> net/bluetooth/hci_conn.c:3038:25: warning: unused variable 'hdev' [-Wunused-variable]
3038 | struct hci_dev *hdev = conn->hdev;
| ^~~~vim +/hdev +3038 net/bluetooth/hci_conn.c
3035
3036 int hci_conn_set_phy(struct hci_conn *conn, u32 phys)
3037 {
> 3038 struct hci_dev *hdev = conn->hdev;
3039 u8 tx_phys, rx_phys;
3040
3041 switch (conn->type) {
3042 case SCO_LINK:
3043 case ESCO_LINK:
3044 return -EINVAL;
3045 case ACL_LINK:
3046 /* Only allow setting BR/EDR PHYs if link type is ACL */
3047 if (phys & ~BT_PHY_BREDR_MASK)
3048 return -EINVAL;
3049
3050 return hci_acl_change_pkt_type(conn,
3051 bt_phy_pkt_type(conn, phys));
3052 case LE_LINK:
3053 /* Only allow setting LE PHYs if link type is LE */
3054 if (phys & ~BT_PHY_LE_MASK)
3055 return -EINVAL;
3056
3057 if (bt_phy_le_phy(phys, &tx_phys, &rx_phys))
3058 return -EINVAL;
3059
3060 return hci_le_set_phy(conn, tx_phys, rx_phys);
3061 default:
3062 return -EINVAL;
3063 }
3064 }
3065
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki