From: Luiz Augusto von Dentz <[email protected]>
This makes MGMT_OP_LOAD_CONN_PARAM update existing connection by
dectecting the request is just for one connection, parameters already
exists and there is a connection.
Since this is a new behavior the revision is also updated to enable
userspace to detect it.
Signed-off-by: Luiz Augusto von Dentz <[email protected]>
---
include/net/bluetooth/hci_sync.h | 3 +++
net/bluetooth/hci_sync.c | 18 +++++++++++++
net/bluetooth/mgmt.c | 45 ++++++++++++++++++++++++++++++--
3 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/include/net/bluetooth/hci_sync.h b/include/net/bluetooth/hci_sync.h
index 6a9d063e9f47..b49057bbdf23 100644
--- a/include/net/bluetooth/hci_sync.h
+++ b/include/net/bluetooth/hci_sync.h
@@ -136,6 +136,7 @@ int hci_suspend_sync(struct hci_dev *hdev);
int hci_resume_sync(struct hci_dev *hdev);
struct hci_conn;
+struct hci_conn_params;
int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason);
@@ -154,3 +155,5 @@ int hci_connect_acl_sync(struct hci_dev *hdev, struct hci_conn *conn);
int hci_connect_le_sync(struct hci_dev *hdev, struct hci_conn *conn);
int hci_cancel_connect_sync(struct hci_dev *hdev, struct hci_conn *conn);
+int hci_le_conn_update_sync(struct hci_dev *hdev, struct hci_conn *conn,
+ struct hci_conn_params *params);
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 891cae8a30da..9f8ef175c251 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -6712,3 +6712,21 @@ int hci_cancel_connect_sync(struct hci_dev *hdev, struct hci_conn *conn)
return -ENOENT;
}
+
+int hci_le_conn_update_sync(struct hci_dev *hdev, struct hci_conn *conn,
+ struct hci_conn_params *params)
+{
+ struct hci_cp_le_conn_update cp;
+
+ memset(&cp, 0, sizeof(cp));
+ cp.handle = cpu_to_le16(conn->handle);
+ cp.conn_interval_min = cpu_to_le16(params->conn_min_interval);
+ cp.conn_interval_max = cpu_to_le16(params->conn_max_interval);
+ cp.conn_latency = cpu_to_le16(params->conn_latency);
+ cp.supervision_timeout = cpu_to_le16(params->supervision_timeout);
+ cp.min_ce_len = cpu_to_le16(0x0000);
+ cp.max_ce_len = cpu_to_le16(0x0000);
+
+ return __hci_cmd_sync_status(hdev, HCI_OP_LE_CONN_UPDATE,
+ sizeof(cp), &cp, HCI_CMD_TIMEOUT);
+}
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 64e66d911c74..db0685300748 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -42,7 +42,7 @@
#include "aosp.h"
#define MGMT_VERSION 1
-#define MGMT_REVISION 22
+#define MGMT_REVISION 23
static const u16 mgmt_commands[] = {
MGMT_OP_READ_INDEX_LIST,
@@ -7874,6 +7874,18 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
return err;
}
+static int conn_update_sync(struct hci_dev *hdev, void *data)
+{
+ struct hci_conn_params *params = data;
+ struct hci_conn *conn;
+
+ conn = hci_conn_hash_lookup_le(hdev, ¶ms->addr, params->addr_type);
+ if (!conn)
+ return -ECANCELED;
+
+ return hci_le_conn_update_sync(hdev, conn, params);
+}
+
static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data,
u16 len)
{
@@ -7907,13 +7919,15 @@ static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data,
hci_dev_lock(hdev);
- hci_conn_params_clear_disabled(hdev);
+ if (i > 1)
+ hci_conn_params_clear_disabled(hdev);
for (i = 0; i < param_count; i++) {
struct mgmt_conn_param *param = &cp->params[i];
struct hci_conn_params *hci_param;
u16 min, max, latency, timeout;
u8 addr_type;
+ bool update;
bt_dev_dbg(hdev, "Adding %pMR (type %u)", ¶m->addr.bdaddr,
param->addr.type);
@@ -7940,6 +7954,19 @@ static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data,
continue;
}
+ /* Detect when the loading is for an existing parameter then
+ * attempt to trigger the connection update procedure.
+ */
+ if (!i && param_count == 1) {
+ hci_param = hci_conn_params_lookup(hdev,
+ ¶m->addr.bdaddr,
+ addr_type);
+ if (hci_param)
+ update = true;
+ else
+ hci_conn_params_clear_disabled(hdev);
+ }
+
hci_param = hci_conn_params_add(hdev, ¶m->addr.bdaddr,
addr_type);
if (!hci_param) {
@@ -7951,6 +7978,20 @@ static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data,
hci_param->conn_max_interval = max;
hci_param->conn_latency = latency;
hci_param->supervision_timeout = timeout;
+
+ if (update) {
+ struct hci_conn *conn;
+
+ conn = hci_conn_hash_lookup_le(hdev, &hci_param->addr,
+ addr_type);
+ if (conn && conn->role == HCI_ROLE_MASTER &&
+ (conn->le_conn_min_interval != min ||
+ conn->le_conn_max_interval != max ||
+ conn->le_conn_latency != latency ||
+ conn->le_supv_timeout != timeout))
+ hci_cmd_sync_queue(hdev, conn_update_sync,
+ hci_param, NULL);
+ }
}
hci_dev_unlock(hdev);
--
2.44.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=852326
---Test result---
Test Summary:
CheckPatch PASS 1.08 seconds
GitLint PASS 0.33 seconds
SubjectPrefix PASS 0.12 seconds
BuildKernel PASS 29.98 seconds
CheckAllWarning PASS 32.82 seconds
CheckSparse PASS 38.14 seconds
CheckSmatch FAIL 36.05 seconds
BuildKernel32 PASS 28.98 seconds
TestRunnerSetup PASS 521.04 seconds
TestRunner_l2cap-tester PASS 20.32 seconds
TestRunner_iso-tester PASS 33.33 seconds
TestRunner_bnep-tester PASS 4.72 seconds
TestRunner_mgmt-tester FAIL 115.22 seconds
TestRunner_rfcomm-tester PASS 7.42 seconds
TestRunner_sco-tester PASS 15.04 seconds
TestRunner_ioctl-tester PASS 7.74 seconds
TestRunner_mesh-tester PASS 5.80 seconds
TestRunner_smp-tester PASS 6.79 seconds
TestRunner_userchan-tester PASS 4.89 seconds
IncrementalBuild PASS 28.11 seconds
Details
##############################
Test: CheckSmatch - FAIL
Desc: Run smatch tool with source
Output:
Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: net/bluetooth/hci_core.o] Error 139
make[4]: *** Deleting file 'net/bluetooth/hci_core.o'
make[3]: *** [scripts/Makefile.build:485: net/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:485: net] Error 2
make[2]: *** Waiting for unfinished jobs....
Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: drivers/bluetooth/bcm203x.o] Error 139
make[4]: *** Deleting file 'drivers/bluetooth/bcm203x.o'
make[4]: *** Waiting for unfinished jobs....
Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: drivers/bluetooth/bpa10x.o] Error 139
make[4]: *** Deleting file 'drivers/bluetooth/bpa10x.o'
make[3]: *** [scripts/Makefile.build:485: drivers/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:485: drivers] Error 2
make[1]: *** [/github/workspace/src/src/Makefile:1919: .] Error 2
make: *** [Makefile:240: __sub-make] Error 2
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 492, Passed: 489 (99.4%), Failed: 1, Not Run: 2
Failed Test Cases
LL Privacy - Remove Device 4 (Disable Adv) Timed out 2.534 seconds
---
Regards,
Linux Bluetooth
Hi Luiz,
kernel test robot noticed the following build warnings:
[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on bluetooth/master linus/master v6.9-rc7 next-20240510]
[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-MGMT-Make-MGMT_OP_LOAD_CONN_PARAM-update-existing-connection/20240510-223834
base: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
patch link: https://lore.kernel.org/r/20240510143645.1408056-1-luiz.dentz%40gmail.com
patch subject: [PATCH v3] Bluetooth: MGMT: Make MGMT_OP_LOAD_CONN_PARAM update existing connection
config: arm-defconfig (https://download.01.org/0day-ci/archive/20240511/[email protected]/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240511/[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/mgmt.c:7922:6: warning: variable 'i' is uninitialized when used here [-Wuninitialized]
if (i > 1)
^
net/bluetooth/mgmt.c:7896:7: note: initialize the variable 'i' to silence this warning
int i;
^
= 0
1 warning generated.
vim +/i +7922 net/bluetooth/mgmt.c
7888
7889 static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data,
7890 u16 len)
7891 {
7892 struct mgmt_cp_load_conn_param *cp = data;
7893 const u16 max_param_count = ((U16_MAX - sizeof(*cp)) /
7894 sizeof(struct mgmt_conn_param));
7895 u16 param_count, expected_len;
7896 int i;
7897
7898 if (!lmp_le_capable(hdev))
7899 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM,
7900 MGMT_STATUS_NOT_SUPPORTED);
7901
7902 param_count = __le16_to_cpu(cp->param_count);
7903 if (param_count > max_param_count) {
7904 bt_dev_err(hdev, "load_conn_param: too big param_count value %u",
7905 param_count);
7906 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM,
7907 MGMT_STATUS_INVALID_PARAMS);
7908 }
7909
7910 expected_len = struct_size(cp, params, param_count);
7911 if (expected_len != len) {
7912 bt_dev_err(hdev, "load_conn_param: expected %u bytes, got %u bytes",
7913 expected_len, len);
7914 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM,
7915 MGMT_STATUS_INVALID_PARAMS);
7916 }
7917
7918 bt_dev_dbg(hdev, "param_count %u", param_count);
7919
7920 hci_dev_lock(hdev);
7921
> 7922 if (i > 1)
7923 hci_conn_params_clear_disabled(hdev);
7924
7925 for (i = 0; i < param_count; i++) {
7926 struct mgmt_conn_param *param = &cp->params[i];
7927 struct hci_conn_params *hci_param;
7928 u16 min, max, latency, timeout;
7929 u8 addr_type;
7930 bool update;
7931
7932 bt_dev_dbg(hdev, "Adding %pMR (type %u)", ¶m->addr.bdaddr,
7933 param->addr.type);
7934
7935 if (param->addr.type == BDADDR_LE_PUBLIC) {
7936 addr_type = ADDR_LE_DEV_PUBLIC;
7937 } else if (param->addr.type == BDADDR_LE_RANDOM) {
7938 addr_type = ADDR_LE_DEV_RANDOM;
7939 } else {
7940 bt_dev_err(hdev, "ignoring invalid connection parameters");
7941 continue;
7942 }
7943
7944 min = le16_to_cpu(param->min_interval);
7945 max = le16_to_cpu(param->max_interval);
7946 latency = le16_to_cpu(param->latency);
7947 timeout = le16_to_cpu(param->timeout);
7948
7949 bt_dev_dbg(hdev, "min 0x%04x max 0x%04x latency 0x%04x timeout 0x%04x",
7950 min, max, latency, timeout);
7951
7952 if (hci_check_conn_params(min, max, latency, timeout) < 0) {
7953 bt_dev_err(hdev, "ignoring invalid connection parameters");
7954 continue;
7955 }
7956
7957 /* Detect when the loading is for an existing parameter then
7958 * attempt to trigger the connection update procedure.
7959 */
7960 if (!i && param_count == 1) {
7961 hci_param = hci_conn_params_lookup(hdev,
7962 ¶m->addr.bdaddr,
7963 addr_type);
7964 if (hci_param)
7965 update = true;
7966 else
7967 hci_conn_params_clear_disabled(hdev);
7968 }
7969
7970 hci_param = hci_conn_params_add(hdev, ¶m->addr.bdaddr,
7971 addr_type);
7972 if (!hci_param) {
7973 bt_dev_err(hdev, "failed to add connection parameters");
7974 continue;
7975 }
7976
7977 hci_param->conn_min_interval = min;
7978 hci_param->conn_max_interval = max;
7979 hci_param->conn_latency = latency;
7980 hci_param->supervision_timeout = timeout;
7981
7982 if (update) {
7983 struct hci_conn *conn;
7984
7985 conn = hci_conn_hash_lookup_le(hdev, &hci_param->addr,
7986 addr_type);
7987 if (conn && conn->role == HCI_ROLE_MASTER &&
7988 (conn->le_conn_min_interval != min ||
7989 conn->le_conn_max_interval != max ||
7990 conn->le_conn_latency != latency ||
7991 conn->le_supv_timeout != timeout))
7992 hci_cmd_sync_queue(hdev, conn_update_sync,
7993 hci_param, NULL);
7994 }
7995 }
7996
7997 hci_dev_unlock(hdev);
7998
7999 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 0,
8000 NULL, 0);
8001 }
8002
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki