From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.70.43.103 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796323307; b=DbC3kB2DBPyqkF3zH9TUnolefbkGE+mGHZfTbF/XbkxC4/Vz3VE+0V1hDRtw4SYb9kUF 1eFf/flW0kQG8uVgpMgCxTSYo5za/YwUFi9fekRHbpok9I/UnsuZY1bNCDCBKrORbLIQA rAaUTvyreMmQyh1FrnNBzGKwnf8+VbJdP7a7C1NlUZpVAGa/iwiUq8yMlrh1+IvK847jF jAhe7HIEz3EsFKyw99y5cn70C4yFyEGsZU8RN1qVlYoKqQBCn9Ru9sykCSP1brDKPF6oi xgJ4ukHMF9QWedIn5iQo8JOqqBpWPXKXXHTNYji/4PP+EbEfCHH/QWMFrE8F6AUsnPQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796323307; h=DMARC-Filter:DKIM-Signature:Date:To:From:Cc:Subject:Message-ID: In-Reply-To:References:Feedback-ID:X-Pm-Message-ID:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=21fVaXDIRz0BtKv0yQmk0sbIn+akDTQHMqyHhImrto8=; b=H71B2HSFcZgLNZmUA3Lhfd2bFmw8BjxSsa1psgxD7WPOu2/YOdCi6plkxW1jev/weeUs wF98ViO6J1ZdEZp5IaYyrZ32imIeOe3us+dKOfY4+1bLoCxHuVCYkbsqC9jSBWjcVwYXr uIvVxOSoQ06gzWCFrPzDl44bgKeCjOlgOGYCLbfYvdoZydKpY1R+/C2MNjDGgu7L5GfM3 PbquM1u/bjrkgHB3Yv/TdO/QE+Qjha6fOAWdOKtaonPfVvs1z3d10+fTVsIKQa8xTTfle DENS9gXmxt3QstSUyh4kK0IVTYCJBhJQvfBgtEgJB7+f5viCFXq9Suef0xHMkBc8Mhw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=enyrcxm2fvbkroefqsca6q5i7m.protonmail2 header.b=JHaEqwog; arc=none smtp.remote-ip=185.70.43.103 Received: from mail-43103.protonmail.ch (mail-43103.protonmail.ch [185.70.43.103]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCCE9606A322 for ; Thu, 3 Dec 2026 18:41:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CCCE9606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=enyrcxm2fvbkroefqsca6q5i7m.protonmail2 header.b=JHaEqwog DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=enyrcxm2fvbkroefqsca6q5i7m.protonmail2; t=1796323301; x=1796582501; bh=21fVaXDIRz0BtKv0yQmk0sbIn+akDTQHMqyHhImrto8=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=JHaEqwogOie/2AFBlZRHXZd2tZTWlK1mM7qkMP/aKTnTIxx2yxG7yvCFXABpgu0bS gFpS8AsC3wEZe6ooigQOibExEthXdcFsakoKp+5AAZc0WhRxKlaU2At2PWpJ268Jn3 /6x6J46AVBeFSFXm0bNgK1q5lUZ2ZNG5L/p87jjfVF7RTkfiWzaxgauhIhcUBK2bK+ BdN3vyhHTt3Csi1yFSa9idLqP/iKMmxFb3dqerrj15/mvGfhl4rPnBHCizLzEscVbz l61ONH26Uf1+oq91whSWqgvLFqst/XgPnAV7CdS8GXDEn8CmULNuQcqXaLyAW+sxxx lqZhpiQMBvR7w== Date: Thu, 03 Dec 2026 18:41:37 +0000 To: linux-bluetooth@vger.kernel.org From: Kyle Pepper Cc: luiz.dentz@gmail.com, marcel@holtmann.org Subject: [RFC PATCH v3 2/2] Bluetooth: Load LE connection event length hints through MGMT Message-ID: <20261203184044.134357-3-cochcoder@proton.me> In-Reply-To: <20261203184044.134357-1-cochcoder@proton.me> References: <20261203184044.134357-1-cochcoder@proton.me> Feedback-ID: 97716137:user:proton X-Pm-Message-ID: 2a9d92a0ab9eccc313cc4833d126a7b7979c3351 X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable LE connection event length hints are connection parameters. Expose them through a privileged per-peer MGMT command instead of the socket option proposed in v2. Keep the existing Load Connection Parameters wire format unchanged. Store the desired hints for future central connections. For an already connected central, queue an LE Connection Update using the current connection parameters and report the result after the matching HCI completion or an error. Zero for both values clears the stored hints. The controller can choose whether to honor the hints. AI assistance: OpenAI GPT-6 (via Codex). Signed-off-by: Kyle Pepper --- diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_c= ore.h index 4aa0b49..ce6ca4e 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -784,6 +784,8 @@ struct hci_conn { =09__u16=09=09le_conn_min_interval; =09__u16=09=09le_conn_max_interval; =09__u16=09=09le_conn_interval; +=09__le16=09=09le_min_ce_len; +=09__le16=09=09le_max_ce_len; =09__u16=09=09le_conn_latency; =09__u16=09=09le_supv_timeout; =09__u16=09=09le_rate_interval; @@ -883,6 +885,8 @@ struct hci_conn_params { =09u16 conn_max_interval; =09u16 conn_latency; =09u16 supervision_timeout; +=09__le16 min_ce_len; +=09__le16 max_ce_len; =20 =09u16 rate_min_interval; =09u16 rate_max_interval; diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h index 17bdd63..7860393 100644 --- a/include/net/bluetooth/mgmt.h +++ b/include/net/bluetooth/mgmt.h @@ -912,6 +912,14 @@ struct mgmt_cp_load_conn_subrate { } __packed; #define MGMT_LOAD_CONN_SUBRATE_SIZE=092 =20 +#define MGMT_OP_LOAD_CONN_EVENT_LEN=090x005D +struct mgmt_cp_load_conn_event_len { +=09struct mgmt_addr_info addr; +=09__le16 min_ce_len; +=09__le16 max_ce_len; +} __packed; +#define MGMT_LOAD_CONN_EVENT_LEN_SIZE=0911 + #define MGMT_EV_CMD_COMPLETE=09=090x0001 struct mgmt_ev_cmd_complete { =09__le16=09opcode; diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index cbad116..3992ac2 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -536,8 +536,8 @@ static int le_conn_update_sync(struct hci_dev *hdev, vo= id *data) =09cp.conn_interval_max=09=3D cpu_to_le16(d->max); =09cp.conn_latency=09=09=3D cpu_to_le16(d->latency); =09cp.supervision_timeout=09=3D cpu_to_le16(d->to_multiplier); -=09cp.min_ce_len=09=09=3D cpu_to_le16(0x0000); -=09cp.max_ce_len=09=09=3D cpu_to_le16(0x0000); +=09cp.min_ce_len=09=09=3D conn->le_min_ce_len; +=09cp.max_ce_len=09=09=3D conn->le_max_ce_len; =09timeout=09=09=09=3D conn->conn_timeout; =20 =09hci_dev_unlock(hdev); diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 67405de..a3e624a 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -7640,8 +7640,8 @@ static void hci_le_remote_conn_param_req_evt(struct h= ci_dev *hdev, void *data, =09cp.interval_max =3D ev->interval_max; =09cp.latency =3D ev->latency; =09cp.timeout =3D ev->timeout; -=09cp.min_ce_len =3D 0; -=09cp.max_ce_len =3D 0; +=09cp.min_ce_len =3D hcon->le_min_ce_len; +=09cp.max_ce_len =3D hcon->le_max_ce_len; =20 =09hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_REPLY, sizeof(cp), &cp); =20 diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 26d438f..a4c4dae 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -7599,8 +7599,8 @@ static void set_ext_conn_params(struct hci_conn *conn= , =09p->conn_interval_max =3D cpu_to_le16(conn->le_conn_max_interval); =09p->conn_latency =3D cpu_to_le16(conn->le_conn_latency); =09p->supervision_timeout =3D cpu_to_le16(conn->le_supv_timeout); -=09p->min_ce_len =3D cpu_to_le16(0x0000); -=09p->max_ce_len =3D cpu_to_le16(0x0000); +=09p->min_ce_len =3D conn->le_min_ce_len; +=09p->max_ce_len =3D conn->le_max_ce_len; } =20 static int hci_le_ext_create_conn_sync(struct hci_dev *hdev, @@ -7703,11 +7703,15 @@ static int hci_le_create_conn_sync(struct hci_dev *= hdev, void *data) =09=09conn->le_conn_max_interval =3D params->conn_max_interval; =09=09conn->le_conn_latency =3D params->conn_latency; =09=09conn->le_supv_timeout =3D params->supervision_timeout; +=09=09conn->le_min_ce_len =3D params->min_ce_len; +=09=09conn->le_max_ce_len =3D params->max_ce_len; =09} else { =09=09conn->le_conn_min_interval =3D hdev->le_conn_min_interval; =09=09conn->le_conn_max_interval =3D hdev->le_conn_max_interval; =09=09conn->le_conn_latency =3D hdev->le_conn_latency; =09=09conn->le_supv_timeout =3D hdev->le_supv_timeout; +=09=09conn->le_min_ce_len =3D 0; +=09=09conn->le_max_ce_len =3D 0; =09} =20 =09hci_dev_unlock(hdev); @@ -7754,8 +7758,8 @@ static int hci_le_create_conn_sync(struct hci_dev *hd= ev, void *data) =09cp.conn_interval_max =3D cpu_to_le16(conn->le_conn_max_interval); =09cp.conn_latency =3D cpu_to_le16(conn->le_conn_latency); =09cp.supervision_timeout =3D cpu_to_le16(conn->le_supv_timeout); -=09cp.min_ce_len =3D cpu_to_le16(0x0000); -=09cp.max_ce_len =3D cpu_to_le16(0x0000); +=09cp.min_ce_len =3D conn->le_min_ce_len; +=09cp.max_ce_len =3D conn->le_max_ce_len; =20 =09/* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 2261: =09 * @@ -8242,14 +8246,21 @@ int hci_le_conn_update_sync(struct hci_dev *hdev, s= truct hci_conn *conn, { =09struct hci_cp_le_conn_update cp; =20 +=09hci_dev_lock(hdev); +=09if (!hci_conn_valid(hdev, conn) || conn->state !=3D BT_CONNECTED) { +=09=09hci_dev_unlock(hdev); +=09=09return -ENOTCONN; +=09} + =09memset(&cp, 0, sizeof(cp)); =09cp.handle=09=09=3D cpu_to_le16(conn->handle); =09cp.conn_interval_min=09=3D cpu_to_le16(params->conn_min_interval); =09cp.conn_interval_max=09=3D cpu_to_le16(params->conn_max_interval); =09cp.conn_latency=09=09=3D cpu_to_le16(params->conn_latency); =09cp.supervision_timeout=09=3D cpu_to_le16(params->supervision_timeout); -=09cp.min_ce_len=09=09=3D cpu_to_le16(0x0000); -=09cp.max_ce_len=09=09=3D cpu_to_le16(0x0000); +=09cp.min_ce_len=09=09=3D conn->le_min_ce_len; +=09cp.max_ce_len=09=09=3D conn->le_max_ce_len; +=09hci_dev_unlock(hdev); =20 =09return __hci_cmd_sync_status(hdev, HCI_OP_LE_CONN_UPDATE, =09=09=09=09 sizeof(cp), &cp, HCI_CMD_TIMEOUT); diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 01969ab..bfbd4f5 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -130,6 +130,7 @@ static const u16 mgmt_commands[] =3D { =09MGMT_OP_MESH_SEND, =09MGMT_OP_MESH_SEND_CANCEL, =09MGMT_OP_HCI_CMD_SYNC, +=09MGMT_OP_LOAD_CONN_EVENT_LEN, }; =20 static const u16 mgmt_events[] =3D { @@ -8590,6 +8591,124 @@ static int load_conn_subrate(struct sock *sk, struc= t hci_dev *hdev, void *data, =09=09=09=09 NULL, 0); } =20 +static int conn_event_len_sync(struct hci_dev *hdev, void *data) +{ +=09struct mgmt_pending_cmd *cmd =3D data; +=09struct mgmt_cp_load_conn_event_len *param =3D cmd->param; +=09struct hci_conn *conn =3D cmd->user_data; +=09struct hci_cp_le_conn_update cp =3D {}; +=09u16 timeout; + +=09hci_dev_lock(hdev); +=09if (!hci_conn_valid(hdev, conn) || conn->state !=3D BT_CONNECTED) { +=09=09hci_dev_unlock(hdev); +=09=09return -ENOTCONN; +=09} + +=09cp.handle =3D cpu_to_le16(conn->handle); +=09cp.conn_interval_min =3D cpu_to_le16(conn->le_conn_interval); +=09cp.conn_interval_max =3D cp.conn_interval_min; +=09cp.conn_latency =3D cpu_to_le16(conn->le_conn_latency); +=09cp.supervision_timeout =3D cpu_to_le16(conn->le_supv_timeout); +=09cp.min_ce_len =3D param->min_ce_len; +=09cp.max_ce_len =3D param->max_ce_len; +=09timeout =3D conn->conn_timeout; +=09hci_dev_unlock(hdev); + +=09return hci_le_conn_update_cmd_sync(hdev, &cp, timeout); +} + +static void conn_event_len_complete(struct hci_dev *hdev, void *data, int = err) +{ +=09struct mgmt_pending_cmd *cmd =3D data; + +=09mgmt_cmd_complete(cmd->sk, hdev->id, cmd->opcode, mgmt_status(err), +=09=09=09 NULL, 0); +=09hci_conn_put(cmd->user_data); +=09mgmt_pending_free(cmd); +} + +static int load_conn_event_len(struct sock *sk, struct hci_dev *hdev, +=09=09=09 void *data, u16 len) +{ +=09struct mgmt_cp_load_conn_event_len *cp =3D data; +=09struct hci_conn_params *params; +=09struct hci_conn *conn; +=09u8 status =3D MGMT_STATUS_SUCCESS; +=09bool new_params; +=09u8 type; + +=09if (!lmp_le_capable(hdev)) +=09=09return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_EVENT_LEN, +=09=09=09=09 MGMT_STATUS_NOT_SUPPORTED); + +=09if (cp->addr.type =3D=3D BDADDR_LE_PUBLIC) +=09=09type =3D ADDR_LE_DEV_PUBLIC; +=09else if (cp->addr.type =3D=3D BDADDR_LE_RANDOM) +=09=09type =3D ADDR_LE_DEV_RANDOM; +=09else +=09=09goto invalid; + +=09if (!bacmp(&cp->addr.bdaddr, BDADDR_ANY) || +=09 le16_to_cpu(cp->min_ce_len) > le16_to_cpu(cp->max_ce_len)) +=09=09goto invalid; + +=09hci_dev_lock(hdev); +=09new_params =3D !hci_conn_params_lookup(hdev, &cp->addr.bdaddr, type); +=09params =3D hci_conn_params_add(hdev, &cp->addr.bdaddr, type); +=09if (!params) { +=09=09status =3D MGMT_STATUS_NO_RESOURCES; +=09=09goto done; +=09} + +=09conn =3D hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, type); +=09if (conn && conn->state =3D=3D BT_CONNECTED && +=09 conn->role =3D=3D HCI_ROLE_MASTER) { +=09=09struct mgmt_pending_cmd *cmd; +=09=09int err; + +=09=09cmd =3D mgmt_pending_new(sk, MGMT_OP_LOAD_CONN_EVENT_LEN, hdev, +=09=09=09=09 data, len); +=09=09if (!cmd) { +=09=09=09status =3D MGMT_STATUS_NO_RESOURCES; +=09=09=09goto rollback; +=09=09} + +=09=09cmd->user_data =3D hci_conn_get(conn); +=09=09err =3D hci_cmd_sync_queue(hdev, conn_event_len_sync, cmd, +=09=09=09=09=09 conn_event_len_complete); +=09=09if (err) { +=09=09=09hci_conn_put(conn); +=09=09=09mgmt_pending_free(cmd); +=09=09=09status =3D mgmt_status(err); +=09=09=09goto rollback; +=09=09} + +=09=09conn->le_min_ce_len =3D cp->min_ce_len; +=09=09conn->le_max_ce_len =3D cp->max_ce_len; +=09=09params->min_ce_len =3D cp->min_ce_len; +=09=09params->max_ce_len =3D cp->max_ce_len; +=09=09hci_dev_unlock(hdev); +=09=09return 0; +=09} + +=09params->min_ce_len =3D cp->min_ce_len; +=09params->max_ce_len =3D cp->max_ce_len; +=09goto done; + +rollback: +=09if (new_params) +=09=09hci_conn_params_free(params); +done: +=09hci_dev_unlock(hdev); +=09return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_CONN_EVENT_LEN, +=09=09=09=09 status, NULL, 0); + +invalid: +=09return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_EVENT_LEN, +=09=09=09 MGMT_STATUS_INVALID_PARAMS); +} + static int set_external_config(struct sock *sk, struct hci_dev *hdev, =09=09=09 void *data, u16 len) { @@ -10058,6 +10177,7 @@ static const struct hci_mgmt_handler mgmt_handlers[= ] =3D { =09{ mgmt_hci_cmd_sync, MGMT_HCI_CMD_SYNC_SIZE, HCI_MGMT_VAR_LEN }, =09{ load_conn_subrate, MGMT_LOAD_CONN_SUBRATE_SIZE, =09=09=09=09=09=09HCI_MGMT_VAR_LEN }, +=09{ load_conn_event_len, MGMT_LOAD_CONN_EVENT_LEN_SIZE }, }; =20 void mgmt_index_added(struct hci_dev *hdev)