Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp544268lqo; Fri, 10 May 2024 07:36:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVIG9pdgxyDGqxHLH7yfrK0WFNTjlnygIPXM3Ubo7ygyo70x6qh/aIbodLmTn29sk6jkEvZW+OMYbwsDuu1E2WnyhqzukkV3g1QOlK/vA== X-Google-Smtp-Source: AGHT+IGdXMtRfq3IaH+JsIyJ9Y9X5Z8XewcvKKf/7HZVtqNrbI7nvQBTM5TKFMt+O+nb9pjHGphq X-Received: by 2002:a50:9353:0:b0:56c:5990:813e with SMTP id 4fb4d7f45d1cf-5734d5bfbd8mr1831582a12.13.1715351818479; Fri, 10 May 2024 07:36:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715351818; cv=pass; d=google.com; s=arc-20160816; b=I1UondFRYyQm0qQuSVQ26khlUOUlMPVtY8X2J2vQgfJp1pNDKmY/4Z+2aBCEeOBRgJ SL5QcHn0KmKDz8+AuKoqEXAupNvDw5q56QJXXO1VWrxTMYNNyoCMv9uFmBG1Yg2pHB2d HjtKC/taPObvTnUsMR37Vsj6P1m7D0IG+yzeGTyf372NCwuNlX+YYGqf5KQ+04Ej0aHA CAfV0YFLNSEDJBAwNDChT8XRREla5Q3C5HvoH6RHW5yh0WX0dTa/SptLWuMuZfmh8pT1 EOg4jXuMuA3q2kJqH8DrWPvd0QzLAp11B7zJrReuA8bxjPQMYFP/zIR0q4GRkbFAUR6M 6cRw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:to:from :dkim-signature; bh=IFsPqmCINRm8kd4KBUP06RMboMfkFzMxGnluIOus0CQ=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=HQ+x4au6Xh+We7jQq9lq5U38U828ohr+/RsJx4FndD00HDb5X6UH33Vzig050xCnm+ Jvv8Oxc7xNN4Go3QxGtkzeLoCGvBrC6W0YXuvc6jANBT98++Qpv0HhgT/fsAKQsXTlG5 Dl4Gpm6lgCAORu36EvDk4vGSJnq3PQN9HHm9OVCWxgefhdnTM5UYIGKd16JA3pYbrYbH S91S+keiGKSllNoMab7G5WMenUjgFIDNnx1DaWIJFx7I/t90TEwEMZZihORYewHHPGa5 ISmjbGxH7LousH5hyw5N7IrvgD999WDPf05pYZJF1RxyW21ohVvsIo65+xxfN7h+tvHZ TSRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QddVGLw7; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-4495-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4495-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c36d4dfsi2003421a12.536.2024.05.10.07.36.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 07:36:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4495-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QddVGLw7; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-4495-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4495-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EF8BD1F25746 for ; Fri, 10 May 2024 14:36:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1274C17085C; Fri, 10 May 2024 14:36:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QddVGLw7" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-vk1-f180.google.com (mail-vk1-f180.google.com [209.85.221.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07172170842 for ; Fri, 10 May 2024 14:36:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715351812; cv=none; b=fjUfnAph39cAT+u8/ZB02qitMH4RBbZuxQcG2X0o848WwN+ZN/GxC9zULvuk2GNo/Ls7Un4BXTXV7FG2iObLGyQ1feqT6yaAlyddHBneQSiriXU4ymfxtysE+oDbq764oYUQl+/ubEYI/MPjMARyMwr6mLmq7ZfWj4VFf9NPop8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715351812; c=relaxed/simple; bh=qThs9NqFl8UkjPEGdTx5WeuQQ4Cv67ZzUfl1Jrjml1k=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Sdl72/bi10KuRftg/5P7G9DQQ3ljGWoYPspw996IfHzY2EhkgvSWgCpELUNYo1eVHNkhuU6me0+IrC14sn3AMOA3oECal7U9UDKFpa2CRdzko1YmSt864v27dADv5MrU/P8WxKU6L5s4AlNe35TAoDLBpURJaooWDiXMZJqoW+o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QddVGLw7; arc=none smtp.client-ip=209.85.221.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-f180.google.com with SMTP id 71dfb90a1353d-4df3e3c674fso778796e0c.2 for ; Fri, 10 May 2024 07:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715351809; x=1715956609; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=IFsPqmCINRm8kd4KBUP06RMboMfkFzMxGnluIOus0CQ=; b=QddVGLw7NQbs/OZJbuU4L0BWlu8Sbcw2HxpmK7qW+lWmmv9j1IqAUi07U4+SY/IXBB 1QkxQkKKRGiIIa9V4dDTH373EDvpmscU7BeX0ueZH0SZjyfUta1WoXUgpCymQOM+POAg 6p+w6WJ8W055dmvXAYZgSlx3sUrIYksfsz8RWNGJ7xV84Kva2eakNAHzIhjMlwsUlWQz DWfNm9RSdqGFMN1RiAEQvWvD+XVpfGYtJajj9DNacZgHBRDR/hkcQbsHMV7mU5vkXYpC 9bfTdht5fLHMhALHTIvl6U1Tta1cZbeueI3PfuomsEMYg9x1rRVkxZJGZBOvtnueNPF5 qmig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715351809; x=1715956609; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IFsPqmCINRm8kd4KBUP06RMboMfkFzMxGnluIOus0CQ=; b=kuyqD5sYosa9cs0Yz9JKkBgM/IQCVnoi8Z4a90+3uKQTvpGWTDxfjplkbqjEM+5v+9 /tA68uj6kW1mosbEczp8AnW/3G07JA2FqexL0gXsAy1+lpU5Vka11/84VDfOoKGhMkct 80hblAIVa/SIIYsAT8YRp3M2QuVL+eyFG7wDFnUumD7hBydSUQ2BFvpkRlPBgXsJbBj3 zkeSR9aMiE2BNCD5Yjzb6CizqVNaFJRTvFka3qUVw1rRYmYsuUWVhqG3qt2oSBMxDNvS dgg5wxpasBymksIY6jeUYe2mAgO5M2mWPWuiruwlR25MbIZSUzrgTENWSOsWi7nO+Ajp 3IZw== X-Gm-Message-State: AOJu0YzurirP+cSwyIyIE3OuKAHXNRTfvnI+8GuZl6gHCHVQ1We7V6Sy 3UC3p9Ad6svIWYSqxVyJwIXSwIIuSlXfRwNhAEtAWY+AEnDzwridaj4FBA== X-Received: by 2002:a05:6122:310a:b0:4dc:a1f6:4406 with SMTP id 71dfb90a1353d-4df882802fdmr3520535e0c.3.1715351808713; Fri, 10 May 2024 07:36:48 -0700 (PDT) Received: from lvondent-mobl4.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-4df7bf79572sm465429e0c.18.2024.05.10.07.36.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 07:36:47 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v3] Bluetooth: MGMT: Make MGMT_OP_LOAD_CONN_PARAM update existing connection Date: Fri, 10 May 2024 10:36:45 -0400 Message-ID: <20240510143645.1408056-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Luiz Augusto von Dentz 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 --- 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