* [RFC PATCH v2 0/2] Bluetooth: LE connection event length requests @ 2026-12-03 1:55 Kyle Pepper 2026-12-03 1:55 ` [RFC PATCH v2 1/2] Bluetooth: Match LE connection update completions Kyle Pepper 2026-12-03 1:55 ` [RFC PATCH v2 2/2] Bluetooth: Add " Kyle Pepper 0 siblings, 2 replies; 7+ messages in thread From: Kyle Pepper @ 2026-12-03 1:55 UTC (permalink / raw) To: linux-bluetooth; +Cc: marcel, luiz.dentz Expose connection-wide advisory CE length hints to connected Central LE sockets so ASHA can request event time and wait for setup before START. First correct synchronous LE update completion matching and error reporting. No controller-specific defaults or connection interval changes are added. The hints are in 0.625 ms units and can be ignored by the controller. The API uses shared last-writer state, not per-socket reservations. Option 23 is provisional. The getter returns native-endian u16 min/max hints and an optional s32 completion status; its full result is eight bytes. AI assistance: Codex (GPT-6). Base: bluetooth-next 7a1a7a5baa1e0f84d0568fc999421ee7dcbccaf5. Changes in v2: patch 1 is unchanged. Patch 2 avoids a recursive device lock on cancellation and balances queue-time references and pending accounting. All other feature code is unchanged. Previous version (human-reported Message-ID; archive fetch unavailable): https://lore.kernel.org/linux-bluetooth/20261202235608.3238527-1-cochcoder@proton.me/ BlueZ companion, already archived: https://lore.kernel.org/linux-bluetooth/20261202160403.226082-1-cochcoder@proton.me/ Validation of v2: defconfig with BT/BT_LE/BT_L2CAP enabled; W=1 hci_conn.o and full net/bluetooth/ including l2cap_sock.o build without warnings. GCC/Clang UBSan tests execute the production callback and setter; the old callback reproduces recursive locking. Unsigned strict CheckPatch is clean with the human sign-off check deferred until DCO certification. The exact source has no hardware, PTS or running-kernel lockdep result. Older integrated N8/MT7922 trials do not establish general controller support. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC PATCH v2 1/2] Bluetooth: Match LE connection update completions 2026-12-03 1:55 [RFC PATCH v2 0/2] Bluetooth: LE connection event length requests Kyle Pepper @ 2026-12-03 1:55 ` Kyle Pepper 2026-12-03 16:00 ` Luiz Augusto von Dentz 2026-12-04 2:11 ` Bluetooth: LE connection event length requests bluez.test.bot 2026-12-03 1:55 ` [RFC PATCH v2 2/2] Bluetooth: Add " Kyle Pepper 1 sibling, 2 replies; 7+ messages in thread From: Kyle Pepper @ 2026-12-03 1:55 UTC (permalink / raw) To: linux-bluetooth; +Cc: marcel, luiz.dentz LE meta dispatch completes synchronous connection updates on the subevent alone and supplies success without checking the event status. An update for another handle, or a failed or truncated update, can release the wait as successful. Match the requested connection handle and require the complete event body before completing the request. Propagate its status while still dispatching unrelated link updates to their normal handler. AI assistance: Codex (GPT-6). Signed-off-by: Kyle Pepper <cochcoder@proton.me> --- Base: bluetooth-next 7a1a7a5baa1e0f84d0568fc999421ee7dcbccaf5. Previous version (human-reported): https://lore.kernel.org/linux-bluetooth/20261202235608.3238527-1-cochcoder@proton.me/ BlueZ companion, already archived: https://lore.kernel.org/linux-bluetooth/20261202160403.226082-1-cochcoder@proton.me/ Offline validation: four W=1 objects; GCC/Clang source-extracted LE dispatch and CE queue tests; getter lengths 0..16 and baseline/negative controls. The exact source has no hardware, PTS or running-kernel lockdep result. Older integrated N8/MT7922 trials do not establish general controller support. diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -8494,11 +8494,29 @@ (hci_opcode_ogf(hci_skb_opcode(hdev->req_skb)) == 0x08 || hci_skb_opcode(hdev->req_skb) == HCI_OP_NOP) && hci_skb_event(hdev->req_skb) == ev->subevent) { + if (hci_skb_opcode(hdev->req_skb) == HCI_OP_LE_CONN_UPDATE) { + struct hci_cp_le_conn_update *cp; + struct hci_ev_le_conn_update_complete *complete; + + if (hdev->req_skb->len < HCI_COMMAND_HDR_SIZE + + sizeof(*cp) || + skb->len < sizeof(*complete)) + goto dispatch; + + cp = (void *)(hdev->req_skb->data + HCI_COMMAND_HDR_SIZE); + complete = (void *)skb->data; + if (cp->handle != complete->handle) + goto dispatch; + + *status = complete->status; + } + *opcode = hci_skb_opcode(hdev->req_skb); - hci_req_cmd_complete(hdev, *opcode, 0x00, req_complete, + hci_req_cmd_complete(hdev, *opcode, *status, req_complete, req_complete_skb); } +dispatch: subev = &hci_le_ev_table[ev->subevent]; if (!subev->func) return; ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH v2 1/2] Bluetooth: Match LE connection update completions 2026-12-03 1:55 ` [RFC PATCH v2 1/2] Bluetooth: Match LE connection update completions Kyle Pepper @ 2026-12-03 16:00 ` Luiz Augusto von Dentz 2026-12-04 2:11 ` Bluetooth: LE connection event length requests bluez.test.bot 1 sibling, 0 replies; 7+ messages in thread From: Luiz Augusto von Dentz @ 2026-12-03 16:00 UTC (permalink / raw) To: Kyle Pepper; +Cc: linux-bluetooth, marcel Hi Kyle, On Wed, Dec 2, 2026 at 8:55 PM Kyle Pepper <cochcoder@proton.me> wrote: > > LE meta dispatch completes synchronous connection updates on the > subevent alone and supplies success without checking the event status. > An update for another handle, or a failed or truncated update, can release > the wait as successful. > > Match the requested connection handle and require the complete event body > before completing the request. Propagate its status while still dispatching > unrelated link updates to their normal handler. This can only happen if the command is not submitted via cmd_sync otherwise there shall only be one outstanding command, if this is caused by the controller spontaneously generating a connection update while a cmd_sync is waiting then we probably need to check the response at caller. > AI assistance: Codex (GPT-6). > > Signed-off-by: Kyle Pepper <cochcoder@proton.me> > --- > Base: bluetooth-next 7a1a7a5baa1e0f84d0568fc999421ee7dcbccaf5. > Previous version (human-reported): > https://lore.kernel.org/linux-bluetooth/20261202235608.3238527-1-cochcoder@proton.me/ > > BlueZ companion, already archived: > https://lore.kernel.org/linux-bluetooth/20261202160403.226082-1-cochcoder@proton.me/ > > Offline validation: four W=1 objects; GCC/Clang source-extracted LE dispatch > and CE queue tests; getter lengths 0..16 and baseline/negative controls. > The exact source has no hardware, PTS or running-kernel lockdep result. > Older integrated N8/MT7922 trials do not establish general controller support. > > diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > --- a/net/bluetooth/hci_event.c > +++ b/net/bluetooth/hci_event.c > @@ -8494,11 +8494,29 @@ > (hci_opcode_ogf(hci_skb_opcode(hdev->req_skb)) == 0x08 || > hci_skb_opcode(hdev->req_skb) == HCI_OP_NOP) && > hci_skb_event(hdev->req_skb) == ev->subevent) { > + if (hci_skb_opcode(hdev->req_skb) == HCI_OP_LE_CONN_UPDATE) { > + struct hci_cp_le_conn_update *cp; > + struct hci_ev_le_conn_update_complete *complete; > + > + if (hdev->req_skb->len < HCI_COMMAND_HDR_SIZE + > + sizeof(*cp) || > + skb->len < sizeof(*complete)) > + goto dispatch; > + > + cp = (void *)(hdev->req_skb->data + HCI_COMMAND_HDR_SIZE); > + complete = (void *)skb->data; > + if (cp->handle != complete->handle) > + goto dispatch; > + > + *status = complete->status; > + } So I assume the following code is what is attempting to complete the request: err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CONN_UPDATE, sizeof(cp), &cp, HCI_EV_LE_CONN_UPDATE_COMPLETE, timeout, NULL); if (err) return err; I think we will probably need to introduce another function to register a custom matcher if matching by event alone doesn't work. That way, we don't have to change the matching logic above constantly. > *opcode = hci_skb_opcode(hdev->req_skb); > - hci_req_cmd_complete(hdev, *opcode, 0x00, req_complete, > + hci_req_cmd_complete(hdev, *opcode, *status, req_complete, > req_complete_skb); > } > > +dispatch: > subev = &hci_le_ev_table[ev->subevent]; > if (!subev->func) > return; > -- Luiz Augusto von Dentz ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Bluetooth: LE connection event length requests 2026-12-03 1:55 ` [RFC PATCH v2 1/2] Bluetooth: Match LE connection update completions Kyle Pepper 2026-12-03 16:00 ` Luiz Augusto von Dentz @ 2026-12-04 2:11 ` bluez.test.bot 1 sibling, 0 replies; 7+ messages in thread From: bluez.test.bot @ 2026-12-04 2:11 UTC (permalink / raw) To: linux-bluetooth, cochcoder [-- Attachment #1: Type: text/plain, Size: 1908 bytes --] 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/series/1230049/ ---Test result--- Test Summary: CheckPatch PASS 2.16 seconds VerifyFixes PASS 0.10 seconds VerifySignedoff PASS 0.09 seconds GitLint PASS 0.51 seconds SubjectPrefix PASS 0.18 seconds BuildKernel PASS 22.68 seconds CheckAllWarning PASS 26.41 seconds CheckSparse WARNING 28.37 seconds BuildKernel32 PASS 22.99 seconds CheckKernelLLVM PASS 25.34 seconds TestRunnerSetup PASS 543.67 seconds TestRunner_l2cap-tester PASS 15.30 seconds TestRunner_iso-tester PASS 11.30 seconds TestRunner_bnep-tester PASS 2.85 seconds TestRunner_mgmt-tester PASS 84.79 seconds TestRunner_rfcomm-tester PASS 4.13 seconds TestRunner_sco-tester PASS 5.13 seconds TestRunner_ioctl-tester PASS 4.25 seconds TestRunner_mesh-tester PASS 4.15 seconds TestRunner_smp-tester PASS 4.00 seconds TestRunner_userchan-tester PASS 2.91 seconds TestRunner_6lowpan-tester PASS 4.10 seconds IncrementalBuild PASS 37.07 seconds Details ############################## 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):net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h): https://github.com/bluez/bluetooth-next/pull/1276 --- Regards, Linux Bluetooth ^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC PATCH v2 2/2] Bluetooth: Add LE connection event length requests 2026-12-03 1:55 [RFC PATCH v2 0/2] Bluetooth: LE connection event length requests Kyle Pepper 2026-12-03 1:55 ` [RFC PATCH v2 1/2] Bluetooth: Match LE connection update completions Kyle Pepper @ 2026-12-03 1:55 ` Kyle Pepper 2026-12-03 16:07 ` Luiz Augusto von Dentz 1 sibling, 1 reply; 7+ messages in thread From: Kyle Pepper @ 2026-12-03 1:55 UTC (permalink / raw) To: linux-bluetooth; +Cc: marcel, luiz.dentz Allow connected Central LE sockets to request advisory connection event length hints without replacing the live interval, latency or timeout. Keep the request on the shared connection and preserve it in later updates. Expose queued or executing work as -EINPROGRESS in an optional extended getter. Report the final error without clearing a newer pending request. Four-byte reads return the requested hint prefix. HCI completion confirms the procedure outcome, not reserved airtime. AI assistance: Codex (GPT-6). Signed-off-by: Kyle Pepper <cochcoder@proton.me> --- Base: bluetooth-next 7a1a7a5baa1e0f84d0568fc999421ee7dcbccaf5. BlueZ companion: https://lore.kernel.org/linux-bluetooth/20261202160403.226082-1-cochcoder@proton.me/ Changes in v2: - Skip locking and completion state on synchronous cancellation. - Take the reference and pending count before queueing; undo both on failure. include/net/bluetooth/bluetooth.h | 13 +++++ include/net/bluetooth/hci_core.h | 5 ++ net/bluetooth/hci_conn.c | 106 +++++++++++++++++++++++++++++++++++++- net/bluetooth/hci_event.c | 4 +- net/bluetooth/hci_sync.c | 13 ++++- net/bluetooth/l2cap_sock.c | 73 ++++++++++++++++++++++++++ 6 files changed, 208 insertions(+), 6 deletions(-) diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 777bc1a03..720d30d63 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -358,6 +358,19 @@ struct bt_codecs { #define BT_SCM_PKT_SEQNUM 0x05 +#define BT_LE_CONN_EVENT_LEN 23 +/* Connection-wide advisory hints in 0.625 ms units; zero is unspecified. */ +struct bt_le_conn_event_len { + __u16 min; + __u16 max; +}; + +struct bt_le_conn_event_len_state { + struct bt_le_conn_event_len request; + /* Zero, -EINPROGRESS, or the last completed request's negative errno. */ + __s32 status; +}; + __printf(1, 2) void bt_info(const char *fmt, ...); __printf(1, 2) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 4aa0b49ae..88c805bd9 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -786,6 +786,10 @@ struct hci_conn { __u16 le_conn_interval; __u16 le_conn_latency; __u16 le_supv_timeout; + __u16 le_min_ce_len; + __u16 le_max_ce_len; + unsigned int le_ce_pending; + int le_ce_status; __u16 le_rate_interval; __u16 le_subrate; __u16 le_rate_latency; @@ -2493,6 +2497,7 @@ 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); +int hci_conn_set_le_event_len(struct hci_conn *conn, u16 min, u16 max); /* ----- HCI Sockets ----- */ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb); diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 5b7526a85..69901d23f 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, void *data) cp.conn_interval_max = cpu_to_le16(d->max); cp.conn_latency = cpu_to_le16(d->latency); cp.supervision_timeout = cpu_to_le16(d->to_multiplier); - cp.min_ce_len = cpu_to_le16(0x0000); - cp.max_ce_len = cpu_to_le16(0x0000); + cp.min_ce_len = cpu_to_le16(conn->le_min_ce_len); + cp.max_ce_len = cpu_to_le16(conn->le_max_ce_len); timeout = conn->conn_timeout; hci_dev_unlock(hdev); @@ -604,6 +604,108 @@ void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency, } } +static int le_conn_event_len_sync(struct hci_dev *hdev, void *data) +{ + struct hci_conn *conn = data; + struct hci_cp_le_conn_update cp = {}; + u16 timeout; + + hci_dev_lock(hdev); + + if (!hci_conn_valid(hdev, conn) || conn->state != BT_CONNECTED) { + hci_dev_unlock(hdev); + return -ENOTCONN; + } + + /* Change only the local hints, preserving the live link parameters. */ + cp.handle = cpu_to_le16(conn->handle); + cp.conn_interval_min = cpu_to_le16(conn->le_conn_interval); + cp.conn_interval_max = cpu_to_le16(conn->le_conn_interval); + cp.conn_latency = cpu_to_le16(conn->le_conn_latency); + cp.supervision_timeout = cpu_to_le16(conn->le_supv_timeout); + cp.min_ce_len = cpu_to_le16(conn->le_min_ce_len); + cp.max_ce_len = cpu_to_le16(conn->le_max_ce_len); + timeout = conn->conn_timeout; + + hci_dev_unlock(hdev); + + return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CONN_UPDATE, + sizeof(cp), &cp, + HCI_EV_LE_CONN_UPDATE_COMPLETE, + timeout, NULL); +} + +static void le_conn_event_len_complete(struct hci_dev *hdev, void *data, + int err) +{ + struct hci_conn *conn = data; + + /* A cancelled entry is completed synchronously from + * hci_cmd_sync_dequeue(), which hci_conn_del() calls with hdev->lock + * already held, so taking it here would self-deadlock. The connection + * is being torn down and nobody can still wait for this request, so + * only drop the reference taken when the request was queued. + */ + if (err == -ECANCELED) + goto done; + + hci_dev_lock(hdev); + /* An older completion must not mark a newer queued request ready. */ + if (!--conn->le_ce_pending) + conn->le_ce_status = err > 0 ? -bt_to_errno(err) : err; + hci_dev_unlock(hdev); + + if (err) + bt_dev_dbg(hdev, "LE connection event length request failed (%d)", + err); + +done: + hci_conn_put(conn); +} + +/* Device must be locked. The values describe the local request, not airtime. */ +int hci_conn_set_le_event_len(struct hci_conn *conn, u16 min, u16 max) +{ + struct hci_dev *hdev = conn->hdev; + u16 old_min, old_max; + int err; + + if (conn->type != LE_LINK || conn->role != HCI_ROLE_MASTER) + return -EOPNOTSUPP; + + if (!hci_conn_valid(hdev, conn) || conn->state != BT_CONNECTED) + return -ENOTCONN; + + if (min > max) + return -EINVAL; + + old_min = conn->le_min_ce_len; + old_max = conn->le_max_ce_len; + conn->le_min_ce_len = min; + conn->le_max_ce_len = max; + + /* Queued work reads the latest request under the device lock. */ + if (hci_cmd_sync_lookup_entry(hdev, le_conn_event_len_sync, conn, + le_conn_event_len_complete)) + return 0; + + hci_conn_get(conn); + conn->le_ce_pending++; + err = hci_cmd_sync_queue(hdev, le_conn_event_len_sync, + conn, + le_conn_event_len_complete); + if (err) { + conn->le_min_ce_len = old_min; + conn->le_max_ce_len = old_max; + conn->le_ce_pending--; + hci_conn_put(conn); + } else { + conn->le_ce_status = -EINPROGRESS; + } + + return err; +} + /* Device _must_ be locked */ void hci_sco_setup(struct hci_conn *conn, __u8 status) { diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index ff5238e8e..afd7e3141 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 hci_dev *hdev, void *data, cp.interval_max = ev->interval_max; cp.latency = ev->latency; cp.timeout = ev->timeout; - cp.min_ce_len = 0; - cp.max_ce_len = 0; + cp.min_ce_len = cpu_to_le16(hcon->le_min_ce_len); + cp.max_ce_len = cpu_to_le16(hcon->le_max_ce_len); hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_REPLY, sizeof(cp), &cp); diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index ee426ffea..f1d0ed7c3 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -8188,14 +8188,23 @@ int hci_le_conn_update_sync(struct hci_dev *hdev, struct hci_conn *conn, { struct hci_cp_le_conn_update cp; + hci_dev_lock(hdev); + + if (!hci_conn_valid(hdev, conn) || conn->state != BT_CONNECTED) { + hci_dev_unlock(hdev); + return -ENOTCONN; + } + 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); + cp.min_ce_len = cpu_to_le16(conn->le_min_ce_len); + cp.max_ce_len = cpu_to_le16(conn->le_max_ce_len); + + hci_dev_unlock(hdev); return __hci_cmd_sync_status(hdev, HCI_OP_LE_CONN_UPDATE, sizeof(cp), &cp, HCI_CMD_TIMEOUT); diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 4e7787ec0..2cbbae604 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -591,6 +591,50 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, return err; } +static int l2cap_sock_conn_event_len(struct sock *sk, + struct bt_le_conn_event_len *len, int *status, bool set) +{ + struct l2cap_chan *chan = l2cap_pi(sk)->chan; + struct l2cap_conn *conn; + bool have_conn; + int err = 0; + + l2cap_chan_lock(chan); + conn = l2cap_chan_conn(chan); + if (!conn) { + l2cap_chan_unlock(chan); + return -ENOTCONN; + } + l2cap_conn_get(conn); + l2cap_chan_unlock(chan); + + /* Match the device -> connection -> channel -> socket lock order. */ + hci_dev_lock(conn->hcon->hdev); + have_conn = l2cap_chan_lock_conn(chan); + lock_sock(sk); + + if (l2cap_chan_conn(chan) != conn || sk->sk_state != BT_CONNECTED || + !hci_conn_valid(conn->hcon->hdev, conn->hcon) || + conn->hcon->state != BT_CONNECTED) { + err = -ENOTCONN; + } else if (conn->hcon->type != LE_LINK) { + err = -EOPNOTSUPP; + } else if (set) { + err = hci_conn_set_le_event_len(conn->hcon, len->min, len->max); + } else { + len->min = conn->hcon->le_min_ce_len; + len->max = conn->hcon->le_max_ce_len; + *status = conn->hcon->le_ce_status; + } + + release_sock(sk); + l2cap_chan_unlock_conn(chan, have_conn); + hci_dev_unlock(conn->hcon->hdev); + l2cap_conn_put(conn); + + return err; +} + static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, sockopt_t *sopt) { @@ -613,6 +657,21 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, return -ENOPROTOOPT; len = sopt->optlen; + if (optname == BT_LE_CONN_EVENT_LEN) { + struct bt_le_conn_event_len_state event_len; + + err = l2cap_sock_conn_event_len(sk, &event_len.request, + &event_len.status, false); + if (err) + return err; + + len = min_t(size_t, len, sizeof(event_len)); + if (copy_to_iter(&event_len, len, &sopt->iter_out) != len) + return -EFAULT; + + sopt->optlen = len; + return 0; + } l2cap_chan_lock(chan); lock_sock(sk); @@ -959,6 +1018,20 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, if (level != SOL_BLUETOOTH) return -ENOPROTOOPT; + if (optname == BT_LE_CONN_EVENT_LEN) { + struct bt_le_conn_event_len event_len; + + if (optlen != sizeof(event_len)) + return -EINVAL; + + err = copy_safe_from_sockptr(&event_len, sizeof(event_len), + optval, optlen); + if (err) + return err; + + return l2cap_sock_conn_event_len(sk, &event_len, NULL, true); + } + l2cap_chan_lock(chan); lock_sock(sk); ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RFC PATCH v2 2/2] Bluetooth: Add LE connection event length requests 2026-12-03 1:55 ` [RFC PATCH v2 2/2] Bluetooth: Add " Kyle Pepper @ 2026-12-03 16:07 ` Luiz Augusto von Dentz 0 siblings, 0 replies; 7+ messages in thread From: Luiz Augusto von Dentz @ 2026-12-03 16:07 UTC (permalink / raw) To: Kyle Pepper; +Cc: linux-bluetooth, marcel Hi Kyle, On Wed, Dec 2, 2026 at 8:55 PM Kyle Pepper <cochcoder@proton.me> wrote: > > Allow connected Central LE sockets to request advisory connection > event length hints without replacing the live interval, latency or timeout. > Keep the request on the shared connection and preserve it in later updates. > > Expose queued or executing work as -EINPROGRESS in an optional extended > getter. Report the final error without clearing a newer pending request. > Four-byte reads return the requested hint prefix. HCI completion confirms > the procedure outcome, not reserved airtime. > > AI assistance: Codex (GPT-6). > > Signed-off-by: Kyle Pepper <cochcoder@proton.me> > --- > Base: bluetooth-next 7a1a7a5baa1e0f84d0568fc999421ee7dcbccaf5. > > BlueZ companion: > https://lore.kernel.org/linux-bluetooth/20261202160403.226082-1-cochcoder@proton.me/ > > Changes in v2: > - Skip locking and completion state on synchronous cancellation. > - Take the reference and pending count before queueing; undo both on failure. > > include/net/bluetooth/bluetooth.h | 13 +++++ > include/net/bluetooth/hci_core.h | 5 ++ > net/bluetooth/hci_conn.c | 106 +++++++++++++++++++++++++++++++++++++- > net/bluetooth/hci_event.c | 4 +- > net/bluetooth/hci_sync.c | 13 ++++- > net/bluetooth/l2cap_sock.c | 73 ++++++++++++++++++++++++++ > 6 files changed, 208 insertions(+), 6 deletions(-) > > diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h > index 777bc1a03..720d30d63 100644 > --- a/include/net/bluetooth/bluetooth.h > +++ b/include/net/bluetooth/bluetooth.h > @@ -358,6 +358,19 @@ struct bt_codecs { > > #define BT_SCM_PKT_SEQNUM 0x05 > > +#define BT_LE_CONN_EVENT_LEN 23 > +/* Connection-wide advisory hints in 0.625 ms units; zero is unspecified. */ > +struct bt_le_conn_event_len { > + __u16 min; > + __u16 max; > +}; > + > +struct bt_le_conn_event_len_state { > + struct bt_le_conn_event_len request; > + /* Zero, -EINPROGRESS, or the last completed request's negative errno. */ > + __s32 status; > +}; I don't think Im willing to add such a sockopt for entering a low level arguments, besides this should really be considered a connection parameter so it probably needs to be loaded with a MGMT command. > __printf(1, 2) > void bt_info(const char *fmt, ...); > __printf(1, 2) > diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h > index 4aa0b49ae..88c805bd9 100644 > --- a/include/net/bluetooth/hci_core.h > +++ b/include/net/bluetooth/hci_core.h > @@ -786,6 +786,10 @@ struct hci_conn { > __u16 le_conn_interval; > __u16 le_conn_latency; > __u16 le_supv_timeout; > + __u16 le_min_ce_len; > + __u16 le_max_ce_len; > + unsigned int le_ce_pending; > + int le_ce_status; > __u16 le_rate_interval; > __u16 le_subrate; > __u16 le_rate_latency; > @@ -2493,6 +2497,7 @@ 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); > +int hci_conn_set_le_event_len(struct hci_conn *conn, u16 min, u16 max); > > /* ----- HCI Sockets ----- */ > void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb); > diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c > index 5b7526a85..69901d23f 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, void *data) > cp.conn_interval_max = cpu_to_le16(d->max); > cp.conn_latency = cpu_to_le16(d->latency); > cp.supervision_timeout = cpu_to_le16(d->to_multiplier); > - cp.min_ce_len = cpu_to_le16(0x0000); > - cp.max_ce_len = cpu_to_le16(0x0000); > + cp.min_ce_len = cpu_to_le16(conn->le_min_ce_len); > + cp.max_ce_len = cpu_to_le16(conn->le_max_ce_len); > timeout = conn->conn_timeout; > > hci_dev_unlock(hdev); > @@ -604,6 +604,108 @@ void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency, > } > } > > +static int le_conn_event_len_sync(struct hci_dev *hdev, void *data) > +{ > + struct hci_conn *conn = data; > + struct hci_cp_le_conn_update cp = {}; > + u16 timeout; > + > + hci_dev_lock(hdev); > + > + if (!hci_conn_valid(hdev, conn) || conn->state != BT_CONNECTED) { > + hci_dev_unlock(hdev); > + return -ENOTCONN; > + } > + > + /* Change only the local hints, preserving the live link parameters. */ > + cp.handle = cpu_to_le16(conn->handle); > + cp.conn_interval_min = cpu_to_le16(conn->le_conn_interval); > + cp.conn_interval_max = cpu_to_le16(conn->le_conn_interval); > + cp.conn_latency = cpu_to_le16(conn->le_conn_latency); > + cp.supervision_timeout = cpu_to_le16(conn->le_supv_timeout); > + cp.min_ce_len = cpu_to_le16(conn->le_min_ce_len); > + cp.max_ce_len = cpu_to_le16(conn->le_max_ce_len); > + timeout = conn->conn_timeout; > + > + hci_dev_unlock(hdev); > + > + return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CONN_UPDATE, > + sizeof(cp), &cp, > + HCI_EV_LE_CONN_UPDATE_COMPLETE, > + timeout, NULL); > +} > + > +static void le_conn_event_len_complete(struct hci_dev *hdev, void *data, > + int err) > +{ > + struct hci_conn *conn = data; > + > + /* A cancelled entry is completed synchronously from > + * hci_cmd_sync_dequeue(), which hci_conn_del() calls with hdev->lock > + * already held, so taking it here would self-deadlock. The connection > + * is being torn down and nobody can still wait for this request, so > + * only drop the reference taken when the request was queued. > + */ > + if (err == -ECANCELED) > + goto done; > + > + hci_dev_lock(hdev); > + /* An older completion must not mark a newer queued request ready. */ > + if (!--conn->le_ce_pending) > + conn->le_ce_status = err > 0 ? -bt_to_errno(err) : err; > + hci_dev_unlock(hdev); > + > + if (err) > + bt_dev_dbg(hdev, "LE connection event length request failed (%d)", > + err); > + > +done: > + hci_conn_put(conn); > +} > + > +/* Device must be locked. The values describe the local request, not airtime. */ > +int hci_conn_set_le_event_len(struct hci_conn *conn, u16 min, u16 max) > +{ > + struct hci_dev *hdev = conn->hdev; > + u16 old_min, old_max; > + int err; > + > + if (conn->type != LE_LINK || conn->role != HCI_ROLE_MASTER) > + return -EOPNOTSUPP; > + > + if (!hci_conn_valid(hdev, conn) || conn->state != BT_CONNECTED) > + return -ENOTCONN; > + > + if (min > max) > + return -EINVAL; > + > + old_min = conn->le_min_ce_len; > + old_max = conn->le_max_ce_len; > + conn->le_min_ce_len = min; > + conn->le_max_ce_len = max; > + > + /* Queued work reads the latest request under the device lock. */ > + if (hci_cmd_sync_lookup_entry(hdev, le_conn_event_len_sync, conn, > + le_conn_event_len_complete)) > + return 0; > + > + hci_conn_get(conn); > + conn->le_ce_pending++; > + err = hci_cmd_sync_queue(hdev, le_conn_event_len_sync, > + conn, > + le_conn_event_len_complete); > + if (err) { > + conn->le_min_ce_len = old_min; > + conn->le_max_ce_len = old_max; > + conn->le_ce_pending--; > + hci_conn_put(conn); > + } else { > + conn->le_ce_status = -EINPROGRESS; > + } > + > + return err; > +} > + > /* Device _must_ be locked */ > void hci_sco_setup(struct hci_conn *conn, __u8 status) > { > diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > index ff5238e8e..afd7e3141 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 hci_dev *hdev, void *data, > cp.interval_max = ev->interval_max; > cp.latency = ev->latency; > cp.timeout = ev->timeout; > - cp.min_ce_len = 0; > - cp.max_ce_len = 0; > + cp.min_ce_len = cpu_to_le16(hcon->le_min_ce_len); > + cp.max_ce_len = cpu_to_le16(hcon->le_max_ce_len); > > hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_REPLY, sizeof(cp), &cp); > > diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c > index ee426ffea..f1d0ed7c3 100644 > --- a/net/bluetooth/hci_sync.c > +++ b/net/bluetooth/hci_sync.c > @@ -8188,14 +8188,23 @@ int hci_le_conn_update_sync(struct hci_dev *hdev, struct hci_conn *conn, > { > struct hci_cp_le_conn_update cp; > > + hci_dev_lock(hdev); > + > + if (!hci_conn_valid(hdev, conn) || conn->state != BT_CONNECTED) { > + hci_dev_unlock(hdev); > + return -ENOTCONN; > + } > + > 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); > + cp.min_ce_len = cpu_to_le16(conn->le_min_ce_len); > + cp.max_ce_len = cpu_to_le16(conn->le_max_ce_len); > + > + hci_dev_unlock(hdev); > > return __hci_cmd_sync_status(hdev, HCI_OP_LE_CONN_UPDATE, > sizeof(cp), &cp, HCI_CMD_TIMEOUT); > diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c > index 4e7787ec0..2cbbae604 100644 > --- a/net/bluetooth/l2cap_sock.c > +++ b/net/bluetooth/l2cap_sock.c > @@ -591,6 +591,50 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, > return err; > } > > +static int l2cap_sock_conn_event_len(struct sock *sk, > + struct bt_le_conn_event_len *len, int *status, bool set) > +{ > + struct l2cap_chan *chan = l2cap_pi(sk)->chan; > + struct l2cap_conn *conn; > + bool have_conn; > + int err = 0; > + > + l2cap_chan_lock(chan); > + conn = l2cap_chan_conn(chan); > + if (!conn) { > + l2cap_chan_unlock(chan); > + return -ENOTCONN; > + } > + l2cap_conn_get(conn); > + l2cap_chan_unlock(chan); > + > + /* Match the device -> connection -> channel -> socket lock order. */ > + hci_dev_lock(conn->hcon->hdev); > + have_conn = l2cap_chan_lock_conn(chan); > + lock_sock(sk); > + > + if (l2cap_chan_conn(chan) != conn || sk->sk_state != BT_CONNECTED || > + !hci_conn_valid(conn->hcon->hdev, conn->hcon) || > + conn->hcon->state != BT_CONNECTED) { > + err = -ENOTCONN; > + } else if (conn->hcon->type != LE_LINK) { > + err = -EOPNOTSUPP; > + } else if (set) { > + err = hci_conn_set_le_event_len(conn->hcon, len->min, len->max); > + } else { > + len->min = conn->hcon->le_min_ce_len; > + len->max = conn->hcon->le_max_ce_len; > + *status = conn->hcon->le_ce_status; > + } > + > + release_sock(sk); > + l2cap_chan_unlock_conn(chan, have_conn); > + hci_dev_unlock(conn->hcon->hdev); > + l2cap_conn_put(conn); > + > + return err; > +} > + > static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, > sockopt_t *sopt) > { > @@ -613,6 +657,21 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, > return -ENOPROTOOPT; > > len = sopt->optlen; > + if (optname == BT_LE_CONN_EVENT_LEN) { > + struct bt_le_conn_event_len_state event_len; > + > + err = l2cap_sock_conn_event_len(sk, &event_len.request, > + &event_len.status, false); > + if (err) > + return err; > + > + len = min_t(size_t, len, sizeof(event_len)); > + if (copy_to_iter(&event_len, len, &sopt->iter_out) != len) > + return -EFAULT; > + > + sopt->optlen = len; > + return 0; > + } > > l2cap_chan_lock(chan); > lock_sock(sk); > @@ -959,6 +1018,20 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, > if (level != SOL_BLUETOOTH) > return -ENOPROTOOPT; > > + if (optname == BT_LE_CONN_EVENT_LEN) { > + struct bt_le_conn_event_len event_len; > + > + if (optlen != sizeof(event_len)) > + return -EINVAL; > + > + err = copy_safe_from_sockptr(&event_len, sizeof(event_len), > + optval, optlen); > + if (err) > + return err; > + > + return l2cap_sock_conn_event_len(sk, &event_len, NULL, true); > + } > + > l2cap_chan_lock(chan); > lock_sock(sk); > > -- Luiz Augusto von Dentz ^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC PATCH 1/2] Bluetooth: Match LE connection update completions
@ 2026-12-02 23:56 Kyle Pepper
2026-12-03 1:17 ` Bluetooth: LE connection event length requests bluez.test.bot
0 siblings, 1 reply; 7+ messages in thread
From: Kyle Pepper @ 2026-12-02 23:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: marcel, luiz.dentz
LE meta dispatch completes synchronous connection updates on the
subevent alone and supplies success without checking the event status.
An update for another handle, or a failed or truncated update, can release
the wait as successful.
Match the requested connection handle and require the complete event body
before completing the request. Propagate its status while still dispatching
unrelated link updates to their normal handler.
AI assistance: Codex (GPT-6).
Signed-off-by: Kyle Pepper <cochcoder@proton.me>
---
Base: bluetooth-next 7a1a7a5baa1e0f84d0568fc999421ee7dcbccaf5.
This is a first public kernel CE RFC; local candidate numbers are not
previous public versions. No kernel CE Message-ID is verified.
BlueZ companion, already archived:
https://lore.kernel.org/linux-bluetooth/20261202160403.226082-1-cochcoder@proton.me/
Offline validation: four W=1 objects; GCC/Clang source-extracted LE dispatch
and CE queue tests; getter lengths 0..16 and baseline/negative controls.
The exact source has no hardware, PTS or running-kernel lockdep result.
Older integrated N8/MT7922 trials do not establish general controller support.
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -8494,11 +8494,29 @@
(hci_opcode_ogf(hci_skb_opcode(hdev->req_skb)) == 0x08 ||
hci_skb_opcode(hdev->req_skb) == HCI_OP_NOP) &&
hci_skb_event(hdev->req_skb) == ev->subevent) {
+ if (hci_skb_opcode(hdev->req_skb) == HCI_OP_LE_CONN_UPDATE) {
+ struct hci_cp_le_conn_update *cp;
+ struct hci_ev_le_conn_update_complete *complete;
+
+ if (hdev->req_skb->len < HCI_COMMAND_HDR_SIZE +
+ sizeof(*cp) ||
+ skb->len < sizeof(*complete))
+ goto dispatch;
+
+ cp = (void *)(hdev->req_skb->data + HCI_COMMAND_HDR_SIZE);
+ complete = (void *)skb->data;
+ if (cp->handle != complete->handle)
+ goto dispatch;
+
+ *status = complete->status;
+ }
+
*opcode = hci_skb_opcode(hdev->req_skb);
- hci_req_cmd_complete(hdev, *opcode, 0x00, req_complete,
+ hci_req_cmd_complete(hdev, *opcode, *status, req_complete,
req_complete_skb);
}
+dispatch:
subev = &hci_le_ev_table[ev->subevent];
if (!subev->func)
return;
^ permalink raw reply [flat|nested] 7+ messages in thread* RE: Bluetooth: LE connection event length requests 2026-12-02 23:56 [RFC PATCH 1/2] Bluetooth: Match LE connection update completions Kyle Pepper @ 2026-12-03 1:17 ` bluez.test.bot 0 siblings, 0 replies; 7+ messages in thread From: bluez.test.bot @ 2026-12-03 1:17 UTC (permalink / raw) To: linux-bluetooth, cochcoder [-- Attachment #1: Type: text/plain, Size: 1908 bytes --] 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/series/1230005/ ---Test result--- Test Summary: CheckPatch PASS 1.99 seconds VerifyFixes PASS 0.06 seconds VerifySignedoff PASS 0.06 seconds GitLint PASS 0.36 seconds SubjectPrefix PASS 0.10 seconds BuildKernel PASS 24.27 seconds CheckAllWarning PASS 27.68 seconds CheckSparse WARNING 29.23 seconds BuildKernel32 PASS 24.31 seconds CheckKernelLLVM PASS 24.53 seconds TestRunnerSetup PASS 563.71 seconds TestRunner_l2cap-tester PASS 15.50 seconds TestRunner_iso-tester PASS 13.63 seconds TestRunner_bnep-tester PASS 2.84 seconds TestRunner_mgmt-tester PASS 85.05 seconds TestRunner_rfcomm-tester PASS 4.15 seconds TestRunner_sco-tester PASS 5.14 seconds TestRunner_ioctl-tester PASS 4.30 seconds TestRunner_mesh-tester PASS 4.12 seconds TestRunner_smp-tester PASS 4.00 seconds TestRunner_userchan-tester PASS 2.88 seconds TestRunner_6lowpan-tester PASS 4.05 seconds IncrementalBuild PASS 40.25 seconds Details ############################## 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):net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h): https://github.com/bluez/bluetooth-next/pull/1275 --- Regards, Linux Bluetooth ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-04 2:11 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-03 1:55 [RFC PATCH v2 0/2] Bluetooth: LE connection event length requests Kyle Pepper 2026-12-03 1:55 ` [RFC PATCH v2 1/2] Bluetooth: Match LE connection update completions Kyle Pepper 2026-12-03 16:00 ` Luiz Augusto von Dentz 2026-12-04 2:11 ` Bluetooth: LE connection event length requests bluez.test.bot 2026-12-03 1:55 ` [RFC PATCH v2 2/2] Bluetooth: Add " Kyle Pepper 2026-12-03 16:07 ` Luiz Augusto von Dentz -- strict thread matches above, loose matches on Subject: below -- 2026-12-02 23:56 [RFC PATCH 1/2] Bluetooth: Match LE connection update completions Kyle Pepper 2026-12-03 1:17 ` Bluetooth: LE connection event length requests bluez.test.bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox