* [RFC PATCH v3 0/2] Bluetooth: Load LE connection event length hints through MGMT
@ 2026-12-03 18:41 Kyle Pepper
2026-12-03 18:41 ` [RFC PATCH v3 1/2] Bluetooth: Allow custom matching of synchronous LE events Kyle Pepper
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Kyle Pepper @ 2026-12-03 18:41 UTC (permalink / raw)
To: linux-bluetooth; +Cc: luiz.dentz, marcel
This series adds a way to supply advisory LE connection event length
hints per peer. It also ensures that an LE connection update completes
the synchronous request for the correct connection.
Changes since v2, in response to Luiz's review:
- Add an optional per-request completion matcher to the synchronous
HCI command path.
- Replace the L2CAP socket option with a privileged MGMT command.
Keep the existing Load Connection Parameters wire format unchanged.
BlueZ needs to switch to the new MGMT command and wait for the reply
before issuing ASHA START.
Validation: both diffs passed strict CheckPatch and the Bluetooth
build passed with W=1. The matcher, event dispatch, and MGMT fixtures
passed under GCC and Clang with UBSan.
AI assistance: OpenAI GPT-6 (via Codex).
Previous revision:
https://lore.kernel.org/linux-bluetooth/20261203015422.3562545-1-cochcoder@proton.me/
base-commit: 7a1a7a5baa1e0f84d0568fc999421ee7dcbccaf5
^ permalink raw reply [flat|nested] 8+ messages in thread* [RFC PATCH v3 1/2] Bluetooth: Allow custom matching of synchronous LE events 2026-12-03 18:41 [RFC PATCH v3 0/2] Bluetooth: Load LE connection event length hints through MGMT Kyle Pepper @ 2026-12-03 18:41 ` Kyle Pepper 2026-12-04 2:10 ` Bluetooth: Load LE connection event length hints through MGMT bluez.test.bot 2026-12-03 18:41 ` [RFC PATCH v3 2/2] " Kyle Pepper 2026-12-04 1:02 ` [RFC PATCH v4 0/2] " Kyle Pepper 2 siblings, 1 reply; 8+ messages in thread From: Kyle Pepper @ 2026-12-03 18:41 UTC (permalink / raw) To: linux-bluetooth; +Cc: luiz.dentz, marcel LE Connection Update Complete includes a connection handle, but the synchronous HCI request can complete on the event code alone. An update for a different connection can therefore complete the wrong request. Allow a synchronous LE event request to install an optional matcher. Use it for LE Connection Update Complete to check the command and event payload lengths, match the connection handle, and return the controller status. Events that do not match still go through normal dispatch. Callers without a matcher keep event-only completion. AI assistance: OpenAI GPT-6 (via Codex). Signed-off-by: Kyle Pepper <cochcoder@proton.me> --- diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 777bc1a..cc0a931 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -572,8 +572,12 @@ int hci_ethtool_ts_info(unsigned int index, int sk_proto, #define HCI_REQ_START BIT(0) #define HCI_REQ_SKB BIT(1) +typedef bool (*hci_req_match_t)(const struct sk_buff *cmd, + const struct sk_buff *event, u8 *status); + struct hci_ctrl { struct sock *sk; + hci_req_match_t req_match; u16 opcode; u8 req_flags; u8 req_event; diff --git a/include/net/bluetooth/hci_sync.h b/include/net/bluetooth/hci_sync.h index eab827d..24cd69d 100644 --- a/include/net/bluetooth/hci_sync.h +++ b/include/net/bluetooth/hci_sync.h @@ -37,6 +37,14 @@ struct hci_cmd_sync_work_entry { }; struct adv_info; +struct hci_cp_le_conn_update; + +int __hci_cmd_sync_le_match(struct hci_dev *hdev, u16 opcode, u32 plen, + const void *param, u8 event, u32 timeout, + hci_req_match_t match); +int hci_le_conn_update_cmd_sync(struct hci_dev *hdev, + const struct hci_cp_le_conn_update *cp, + u32 timeout); struct sk_buff *hci_cmd_sync_alloc(struct hci_dev *hdev, u16 opcode, u32 plen, const void *param, struct sock *sk); diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 5b7526a..cbad116 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -542,10 +542,7 @@ static int le_conn_update_sync(struct hci_dev *hdev, void *data) hci_dev_unlock(hdev); - err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CONN_UPDATE, - sizeof(cp), &cp, - HCI_EV_LE_CONN_UPDATE_COMPLETE, - timeout, NULL); + err = hci_le_conn_update_cmd_sync(hdev, &cp, timeout); if (err) return err; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 749963d..67405de 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -8486,18 +8486,28 @@ static void hci_le_meta_evt(struct hci_dev *hdev, void *data, { struct hci_ev_le_meta *ev = data; const struct hci_le_ev *subev; + struct sk_buff *cmd; + hci_req_match_t match; + u8 result = 0; bt_dev_dbg(hdev, "subevent 0x%2.2x", ev->subevent); /* Only match event if command OGF is for LE */ - if (hdev->req_skb && - (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) { - *opcode = hci_skb_opcode(hdev->req_skb); - hci_req_cmd_complete(hdev, *opcode, 0x00, req_complete, - req_complete_skb); + hci_dev_lock(hdev); + cmd = hdev->req_skb; + if (cmd && (hci_opcode_ogf(hci_skb_opcode(cmd)) == 0x08 || + hci_skb_opcode(cmd) == HCI_OP_NOP) && + hci_skb_event(cmd) == ev->subevent) { + match = bt_cb(cmd)->hci.req_match; + if (!match || (READ_ONCE(hdev->req_status) == HCI_REQ_PEND && + match(cmd, skb, &result))) { + *opcode = hci_skb_opcode(cmd); + *status = result; + hci_req_cmd_complete(hdev, *opcode, result, req_complete, + req_complete_skb); + } } + hci_dev_unlock(hdev); subev = &hci_le_ev_table[ev->subevent]; if (!subev->func) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index ee426ff..26d438f 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -74,6 +74,7 @@ struct sk_buff *hci_cmd_sync_alloc(struct hci_dev *hdev, u16 opcode, u32 plen, hci_skb_pkt_type(skb) = HCI_COMMAND_PKT; hci_skb_opcode(skb) = opcode; + bt_cb(skb)->hci.req_match = NULL; /* Grab a reference if command needs to be associated with a sock (e.g. * likely mgmt socket that initiated the command). @@ -87,7 +88,8 @@ struct sk_buff *hci_cmd_sync_alloc(struct hci_dev *hdev, u16 opcode, u32 plen, } static void hci_cmd_sync_add(struct hci_request *req, u16 opcode, u32 plen, - const void *param, u8 event, struct sock *sk) + const void *param, u8 event, struct sock *sk, + hci_req_match_t match) { struct hci_dev *hdev = req->hdev; struct sk_buff *skb; @@ -112,6 +114,7 @@ static void hci_cmd_sync_add(struct hci_request *req, u16 opcode, u32 plen, bt_cb(skb)->hci.req_flags |= HCI_REQ_START; hci_skb_event(skb) = event; + bt_cb(skb)->hci.req_match = match; skb_queue_tail(&req->cmd_q, skb); } @@ -157,9 +160,10 @@ static void hci_request_init(struct hci_request *req, struct hci_dev *hdev) } /* This function requires the caller holds hdev->req_lock. */ -struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen, - const void *param, u8 event, u32 timeout, - struct sock *sk) +static struct sk_buff *hci_cmd_sync_match(struct hci_dev *hdev, u16 opcode, + u32 plen, const void *param, + u8 event, u32 timeout, struct sock *sk, + hci_req_match_t match) { struct hci_request req; struct sk_buff *skb; @@ -169,7 +173,7 @@ struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen, hci_request_init(&req, hdev); - hci_cmd_sync_add(&req, opcode, plen, param, event, sk); + hci_cmd_sync_add(&req, opcode, plen, param, event, sk, match); WRITE_ONCE(hdev->req_status, HCI_REQ_PEND); @@ -218,8 +222,58 @@ struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen, return skb; } + +struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen, + const void *param, u8 event, u32 timeout, + struct sock *sk) +{ + return hci_cmd_sync_match(hdev, opcode, plen, param, event, timeout, sk, + NULL); +} EXPORT_SYMBOL(__hci_cmd_sync_sk); +int __hci_cmd_sync_le_match(struct hci_dev *hdev, u16 opcode, u32 plen, + const void *param, u8 event, u32 timeout, + hci_req_match_t match) +{ + struct sk_buff *skb; + + skb = hci_cmd_sync_match(hdev, opcode, plen, param, event, timeout, NULL, + match); + if (IS_ERR(skb)) + return PTR_ERR(skb) == -ENODATA ? 0 : PTR_ERR(skb); + + kfree_skb(skb); + return 0; +} + +static bool le_conn_update_match(const struct sk_buff *cmd, + const struct sk_buff *event, u8 *status) +{ + struct hci_ev_le_conn_update_complete ev_buf; + struct hci_cp_le_conn_update cp_buf; + const struct hci_ev_le_conn_update_complete *ev; + const struct hci_cp_le_conn_update *cp; + + cp = skb_header_pointer(cmd, HCI_COMMAND_HDR_SIZE, sizeof(cp_buf), + &cp_buf); + ev = skb_header_pointer(event, 0, sizeof(ev_buf), &ev_buf); + if (!cp || !ev || cp->handle != ev->handle) + return false; + + *status = ev->status; + return true; +} + +int hci_le_conn_update_cmd_sync(struct hci_dev *hdev, + const struct hci_cp_le_conn_update *cp, + u32 timeout) +{ + return __hci_cmd_sync_le_match(hdev, HCI_OP_LE_CONN_UPDATE, sizeof(*cp), + cp, HCI_EV_LE_CONN_UPDATE_COMPLETE, + timeout, le_conn_update_match); +} + /* This function requires the caller holds hdev->req_lock. */ struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, const void *param, u32 timeout) ^ permalink raw reply related [flat|nested] 8+ messages in thread
* RE: Bluetooth: Load LE connection event length hints through MGMT 2026-12-03 18:41 ` [RFC PATCH v3 1/2] Bluetooth: Allow custom matching of synchronous LE events Kyle Pepper @ 2026-12-04 2:10 ` bluez.test.bot 0 siblings, 0 replies; 8+ messages in thread From: bluez.test.bot @ 2026-12-04 2:10 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/1231010/ ---Test result--- Test Summary: CheckPatch PASS 2.18 seconds VerifyFixes PASS 0.04 seconds VerifySignedoff PASS 0.04 seconds GitLint PASS 0.30 seconds SubjectPrefix PASS 0.08 seconds BuildKernel PASS 20.77 seconds CheckAllWarning PASS 23.91 seconds CheckSparse WARNING 25.24 seconds BuildKernel32 PASS 20.66 seconds CheckKernelLLVM PASS 20.35 seconds TestRunnerSetup PASS 480.91 seconds TestRunner_l2cap-tester PASS 14.31 seconds TestRunner_iso-tester PASS 11.71 seconds TestRunner_bnep-tester PASS 3.12 seconds TestRunner_mgmt-tester PASS 84.60 seconds TestRunner_rfcomm-tester PASS 4.40 seconds TestRunner_sco-tester PASS 5.41 seconds TestRunner_ioctl-tester PASS 4.47 seconds TestRunner_mesh-tester PASS 4.38 seconds TestRunner_smp-tester PASS 4.27 seconds TestRunner_userchan-tester PASS 3.16 seconds TestRunner_6lowpan-tester PASS 4.34 seconds IncrementalBuild PASS 31.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/1282 --- Regards, Linux Bluetooth ^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFC PATCH v3 2/2] Bluetooth: Load LE connection event length hints through MGMT 2026-12-03 18:41 [RFC PATCH v3 0/2] Bluetooth: Load LE connection event length hints through MGMT Kyle Pepper 2026-12-03 18:41 ` [RFC PATCH v3 1/2] Bluetooth: Allow custom matching of synchronous LE events Kyle Pepper @ 2026-12-03 18:41 ` Kyle Pepper 2026-12-04 1:02 ` [RFC PATCH v4 0/2] " Kyle Pepper 2 siblings, 0 replies; 8+ messages in thread From: Kyle Pepper @ 2026-12-03 18:41 UTC (permalink / raw) To: linux-bluetooth; +Cc: luiz.dentz, marcel 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 <cochcoder@proton.me> --- diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.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 { __u16 le_conn_min_interval; __u16 le_conn_max_interval; __u16 le_conn_interval; + __le16 le_min_ce_len; + __le16 le_max_ce_len; __u16 le_conn_latency; __u16 le_supv_timeout; __u16 le_rate_interval; @@ -883,6 +885,8 @@ struct hci_conn_params { u16 conn_max_interval; u16 conn_latency; u16 supervision_timeout; + __le16 min_ce_len; + __le16 max_ce_len; u16 rate_min_interval; u16 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 2 +#define MGMT_OP_LOAD_CONN_EVENT_LEN 0x005D +struct mgmt_cp_load_conn_event_len { + struct mgmt_addr_info addr; + __le16 min_ce_len; + __le16 max_ce_len; +} __packed; +#define MGMT_LOAD_CONN_EVENT_LEN_SIZE 11 + #define MGMT_EV_CMD_COMPLETE 0x0001 struct mgmt_ev_cmd_complete { __le16 opcode; 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, 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 = conn->le_min_ce_len; + cp.max_ce_len = conn->le_max_ce_len; timeout = conn->conn_timeout; hci_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 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 = hcon->le_min_ce_len; + cp.max_ce_len = 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 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, p->conn_interval_max = cpu_to_le16(conn->le_conn_max_interval); p->conn_latency = cpu_to_le16(conn->le_conn_latency); p->supervision_timeout = cpu_to_le16(conn->le_supv_timeout); - p->min_ce_len = cpu_to_le16(0x0000); - p->max_ce_len = cpu_to_le16(0x0000); + p->min_ce_len = conn->le_min_ce_len; + p->max_ce_len = conn->le_max_ce_len; } 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) conn->le_conn_max_interval = params->conn_max_interval; conn->le_conn_latency = params->conn_latency; conn->le_supv_timeout = params->supervision_timeout; + conn->le_min_ce_len = params->min_ce_len; + conn->le_max_ce_len = params->max_ce_len; } else { conn->le_conn_min_interval = hdev->le_conn_min_interval; conn->le_conn_max_interval = hdev->le_conn_max_interval; conn->le_conn_latency = hdev->le_conn_latency; conn->le_supv_timeout = hdev->le_supv_timeout; + conn->le_min_ce_len = 0; + conn->le_max_ce_len = 0; } hci_dev_unlock(hdev); @@ -7754,8 +7758,8 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data) cp.conn_interval_max = cpu_to_le16(conn->le_conn_max_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(0x0000); - cp.max_ce_len = cpu_to_le16(0x0000); + cp.min_ce_len = conn->le_min_ce_len; + cp.max_ce_len = conn->le_max_ce_len; /* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 2261: * @@ -8242,14 +8246,21 @@ 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 = conn->le_min_ce_len; + cp.max_ce_len = 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/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[] = { MGMT_OP_MESH_SEND, MGMT_OP_MESH_SEND_CANCEL, MGMT_OP_HCI_CMD_SYNC, + MGMT_OP_LOAD_CONN_EVENT_LEN, }; static const u16 mgmt_events[] = { @@ -8590,6 +8591,124 @@ static int load_conn_subrate(struct sock *sk, struct hci_dev *hdev, void *data, NULL, 0); } +static int conn_event_len_sync(struct hci_dev *hdev, void *data) +{ + struct mgmt_pending_cmd *cmd = data; + struct mgmt_cp_load_conn_event_len *param = cmd->param; + struct hci_conn *conn = cmd->user_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; + } + + cp.handle = cpu_to_le16(conn->handle); + cp.conn_interval_min = cpu_to_le16(conn->le_conn_interval); + cp.conn_interval_max = cp.conn_interval_min; + cp.conn_latency = cpu_to_le16(conn->le_conn_latency); + cp.supervision_timeout = cpu_to_le16(conn->le_supv_timeout); + cp.min_ce_len = param->min_ce_len; + cp.max_ce_len = param->max_ce_len; + timeout = conn->conn_timeout; + hci_dev_unlock(hdev); + + return hci_le_conn_update_cmd_sync(hdev, &cp, timeout); +} + +static void conn_event_len_complete(struct hci_dev *hdev, void *data, int err) +{ + struct mgmt_pending_cmd *cmd = data; + + mgmt_cmd_complete(cmd->sk, hdev->id, cmd->opcode, mgmt_status(err), + NULL, 0); + hci_conn_put(cmd->user_data); + mgmt_pending_free(cmd); +} + +static int load_conn_event_len(struct sock *sk, struct hci_dev *hdev, + void *data, u16 len) +{ + struct mgmt_cp_load_conn_event_len *cp = data; + struct hci_conn_params *params; + struct hci_conn *conn; + u8 status = MGMT_STATUS_SUCCESS; + bool new_params; + u8 type; + + if (!lmp_le_capable(hdev)) + return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_EVENT_LEN, + MGMT_STATUS_NOT_SUPPORTED); + + if (cp->addr.type == BDADDR_LE_PUBLIC) + type = ADDR_LE_DEV_PUBLIC; + else if (cp->addr.type == BDADDR_LE_RANDOM) + type = ADDR_LE_DEV_RANDOM; + else + goto invalid; + + if (!bacmp(&cp->addr.bdaddr, BDADDR_ANY) || + le16_to_cpu(cp->min_ce_len) > le16_to_cpu(cp->max_ce_len)) + goto invalid; + + hci_dev_lock(hdev); + new_params = !hci_conn_params_lookup(hdev, &cp->addr.bdaddr, type); + params = hci_conn_params_add(hdev, &cp->addr.bdaddr, type); + if (!params) { + status = MGMT_STATUS_NO_RESOURCES; + goto done; + } + + conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, type); + if (conn && conn->state == BT_CONNECTED && + conn->role == HCI_ROLE_MASTER) { + struct mgmt_pending_cmd *cmd; + int err; + + cmd = mgmt_pending_new(sk, MGMT_OP_LOAD_CONN_EVENT_LEN, hdev, + data, len); + if (!cmd) { + status = MGMT_STATUS_NO_RESOURCES; + goto rollback; + } + + cmd->user_data = hci_conn_get(conn); + err = hci_cmd_sync_queue(hdev, conn_event_len_sync, cmd, + conn_event_len_complete); + if (err) { + hci_conn_put(conn); + mgmt_pending_free(cmd); + status = mgmt_status(err); + goto rollback; + } + + conn->le_min_ce_len = cp->min_ce_len; + conn->le_max_ce_len = cp->max_ce_len; + params->min_ce_len = cp->min_ce_len; + params->max_ce_len = cp->max_ce_len; + hci_dev_unlock(hdev); + return 0; + } + + params->min_ce_len = cp->min_ce_len; + params->max_ce_len = cp->max_ce_len; + goto done; + +rollback: + if (new_params) + hci_conn_params_free(params); +done: + hci_dev_unlock(hdev); + return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_CONN_EVENT_LEN, + status, NULL, 0); + +invalid: + return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_EVENT_LEN, + MGMT_STATUS_INVALID_PARAMS); +} + static int set_external_config(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) { @@ -10058,6 +10177,7 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { { mgmt_hci_cmd_sync, MGMT_HCI_CMD_SYNC_SIZE, HCI_MGMT_VAR_LEN }, { load_conn_subrate, MGMT_LOAD_CONN_SUBRATE_SIZE, HCI_MGMT_VAR_LEN }, + { load_conn_event_len, MGMT_LOAD_CONN_EVENT_LEN_SIZE }, }; void mgmt_index_added(struct hci_dev *hdev) ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [RFC PATCH v4 0/2] Bluetooth: Load LE connection event length hints through MGMT 2026-12-03 18:41 [RFC PATCH v3 0/2] Bluetooth: Load LE connection event length hints through MGMT Kyle Pepper 2026-12-03 18:41 ` [RFC PATCH v3 1/2] Bluetooth: Allow custom matching of synchronous LE events Kyle Pepper 2026-12-03 18:41 ` [RFC PATCH v3 2/2] " Kyle Pepper @ 2026-12-04 1:02 ` Kyle Pepper 2026-12-04 1:03 ` [RFC PATCH v4 1/2] Bluetooth: Allow custom matching of synchronous LE events Kyle Pepper 2026-12-04 1:03 ` [RFC PATCH v4 2/2] " Kyle Pepper 2 siblings, 2 replies; 8+ messages in thread From: Kyle Pepper @ 2026-12-04 1:02 UTC (permalink / raw) To: linux-bluetooth; +Cc: luiz.dentz, marcel Expose advisory LE connection event length hints through a privileged per-peer MGMT command. Match LE Connection Update Complete against the pending command's connection handle before reporting a live update result. Changes since RFC v3: - Keep the matcher on hci_dev and clean up matched requests on every exit. - Resolve an initiating peer's identity and snapshot the hints for both legacy and extended create commands. - Handle configuring and connecting central links, preserve active SCI and subrate settings, and store live changes only after HCI success. - Use an HCI command timeout when unset, report timeout and disconnect distinctly, and avoid allocating an entry to clear an unknown peer. RFC v3 cover (Message-ID from the human send receipt): https://lore.kernel.org/linux-bluetooth/20261203184044.134357-1-cochcoder@proton.me/ Codex assisted with the source revisions and offline verification. AI assistance: v4 Kyle Pepper (2): Bluetooth: Allow custom matching of synchronous LE events Bluetooth: Load LE connection event length hints through MGMT include/net/bluetooth/bluetooth.h | 14 +++ include/net/bluetooth/hci_core.h | 6 + include/net/bluetooth/hci_sync.h | 9 ++ include/net/bluetooth/mgmt.h | 8 ++ net/bluetooth/hci_conn.c | 9 +- net/bluetooth/hci_event.c | 33 +++-- net/bluetooth/hci_sync.c | 198 +++++++++++++++++++++++++----- net/bluetooth/mgmt.c | 163 ++++++++++++++++++++++++ 8 files changed, 393 insertions(+), 47 deletions(-) base-commit: 7a1a7a5baa1e0f84d0568fc999421ee7dcbccaf5 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFC PATCH v4 1/2] Bluetooth: Allow custom matching of synchronous LE events 2026-12-04 1:02 ` [RFC PATCH v4 0/2] " Kyle Pepper @ 2026-12-04 1:03 ` Kyle Pepper 2026-12-04 2:19 ` Bluetooth: Load LE connection event length hints through MGMT bluez.test.bot 2026-12-04 1:03 ` [RFC PATCH v4 2/2] " Kyle Pepper 1 sibling, 1 reply; 8+ messages in thread From: Kyle Pepper @ 2026-12-04 1:03 UTC (permalink / raw) To: linux-bluetooth; +Cc: luiz.dentz, marcel LE Connection Update Complete includes a connection handle, but the synchronous HCI request can complete on the event code alone. An update for a different connection can therefore complete the wrong request. Allow a synchronous LE event request to install an optional matcher. Use it for LE Connection Update Complete to check the command and event payload lengths, match the connection handle, and return the controller status. Events that do not match still go through normal dispatch. Callers without a matcher keep event-only completion. Codex assisted with the matcher and request cleanup changes. AI assistance: v4 Signed-off-by: Kyle Pepper <cochcoder@proton.me> --- include/net/bluetooth/bluetooth.h | 14 +++ include/net/bluetooth/hci_core.h | 2 + include/net/bluetooth/hci_sync.h | 9 ++ net/bluetooth/hci_conn.c | 5 +- net/bluetooth/hci_event.c | 29 ++++-- net/bluetooth/hci_sync.c | 147 ++++++++++++++++++++++++++---- 6 files changed, 176 insertions(+), 30 deletions(-) diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 777bc1a03..58f8a7186 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -572,6 +572,20 @@ int hci_ethtool_ts_info(unsigned int index, int sk_proto, #define HCI_REQ_START BIT(0) #define HCI_REQ_SKB BIT(1) +/** + * typedef hci_req_match_t - match an LE event against a pending sync command + * @cmd: pending command, starting at its HCI command header + * @event: LE Meta event, starting at the LE subevent payload + * @status: completion status, set only on a match + * + * Called from hci_le_meta_evt() with hdev->lock held; must not sleep. + * The caller arming the request holds hdev->req_lock. + * + * Return: true if @event completes @cmd and @status was set, else false. + */ +typedef bool (*hci_req_match_t)(const struct sk_buff *cmd, + const struct sk_buff *event, u8 *status); + struct hci_ctrl { struct sock *sk; u16 opcode; diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 4aa0b49ae..106fc41a6 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -546,6 +546,8 @@ struct hci_dev { __u32 req_status; __u32 req_result; struct sk_buff *req_skb; + /* Protected by hdev->lock; the sync request owner holds req_lock. */ + hci_req_match_t req_match; struct sk_buff *req_rsp; void *smp_data; diff --git a/include/net/bluetooth/hci_sync.h b/include/net/bluetooth/hci_sync.h index eab827dfa..d09fb2c06 100644 --- a/include/net/bluetooth/hci_sync.h +++ b/include/net/bluetooth/hci_sync.h @@ -37,6 +37,15 @@ struct hci_cmd_sync_work_entry { }; struct adv_info; +struct hci_cp_le_conn_update; + +/* Wait for LE Connection Update Complete for cp->handle. The caller must + * hold hdev->req_lock and pass a positive timeout in jiffies. + * Returns 0 or a negative errno. + */ +int hci_le_conn_update_wait_sync(struct hci_dev *hdev, + const struct hci_cp_le_conn_update *cp, + u32 timeout); struct sk_buff *hci_cmd_sync_alloc(struct hci_dev *hdev, u16 opcode, u32 plen, const void *param, struct sock *sk); diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 5b7526a85..f37459d41 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -542,10 +542,7 @@ static int le_conn_update_sync(struct hci_dev *hdev, void *data) hci_dev_unlock(hdev); - err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CONN_UPDATE, - sizeof(cp), &cp, - HCI_EV_LE_CONN_UPDATE_COMPLETE, - timeout, NULL); + err = hci_le_conn_update_wait_sync(hdev, &cp, timeout); if (err) return err; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 749963d0c..a6c4fb486 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -8486,17 +8486,30 @@ static void hci_le_meta_evt(struct hci_dev *hdev, void *data, { struct hci_ev_le_meta *ev = data; const struct hci_le_ev *subev; + struct sk_buff *cmd; + hci_req_match_t match; + u8 result = 0; bt_dev_dbg(hdev, "subevent 0x%2.2x", ev->subevent); - /* Only match event if command OGF is for LE */ - if (hdev->req_skb && - (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) { - *opcode = hci_skb_opcode(hdev->req_skb); - hci_req_cmd_complete(hdev, *opcode, 0x00, req_complete, - req_complete_skb); + /* Avoid taking hdev->lock for reports with no pending command. */ + if (READ_ONCE(hdev->req_skb)) { + hci_dev_lock(hdev); + cmd = hdev->req_skb; + if (cmd && (hci_opcode_ogf(hci_skb_opcode(cmd)) == 0x08 || + hci_skb_opcode(cmd) == HCI_OP_NOP) && + hci_skb_event(cmd) == ev->subevent) { + match = hdev->req_match; + if (!match || + (READ_ONCE(hdev->req_status) == HCI_REQ_PEND && + match(cmd, skb, &result))) { + *opcode = hci_skb_opcode(cmd); + *status = result; + hci_req_cmd_complete(hdev, *opcode, result, req_complete, + req_complete_skb); + } + } + hci_dev_unlock(hdev); } subev = &hci_le_ev_table[ev->subevent]; diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index ee426ffea..ef1009632 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -20,6 +20,18 @@ #include "aosp.h" #include "leds.h" +static void hci_cmd_sync_clear_req_skb(struct hci_dev *hdev) +{ + if (hdev->req_skb) { + struct sock *sk = hci_skb_sk(hdev->req_skb); + + if (sk) + sock_put(sk); + } + kfree_skb(hdev->req_skb); + hdev->req_skb = NULL; +} + static void hci_cmd_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode, struct sk_buff *skb) { @@ -36,14 +48,7 @@ static void hci_cmd_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode, * response skb doesn't carry it. */ hci_dev_lock(hdev); - if (hdev->req_skb) { - struct sock *sk = hci_skb_sk(hdev->req_skb); - - if (sk) - sock_put(sk); - } - kfree_skb(hdev->req_skb); - hdev->req_skb = NULL; + hci_cmd_sync_clear_req_skb(hdev); hci_dev_unlock(hdev); if (skb) @@ -156,10 +161,49 @@ static void hci_request_init(struct hci_request *req, struct hci_dev *hdev) req->err = 0; } +static void hci_req_match_set(struct hci_dev *hdev, hci_req_match_t match) +{ + hci_dev_lock(hdev); + hdev->req_match = match; + hci_dev_unlock(hdev); +} + +struct hci_req_match_cleanup { + struct work_struct work; + struct hci_dev *hdev; +}; + +static void hci_cmd_sync_match_abort_work(struct work_struct *work) +{ + struct hci_req_match_cleanup *cleanup = + container_of(work, struct hci_req_match_cleanup, work); + struct hci_dev *hdev = cleanup->hdev; + + hci_dev_lock(hdev); + hci_dev_clear_flag(hdev, HCI_CMD_PENDING); + hci_cmd_sync_clear_req_skb(hdev); + if (READ_ONCE(hdev->req_status) == HCI_REQ_PEND) + WRITE_ONCE(hdev->req_status, 0); + hdev->req_match = NULL; + hci_dev_unlock(hdev); +} + +/* Serialize cleanup with command sending and event readers of req_skb. */ +static void hci_cmd_sync_match_abort(struct hci_dev *hdev) +{ + struct hci_req_match_cleanup cleanup = { .hdev = hdev }; + + INIT_WORK_ONSTACK(&cleanup.work, hci_cmd_sync_match_abort_work); + queue_work(hdev->workqueue, &cleanup.work); + flush_work(&cleanup.work); + destroy_work_on_stack(&cleanup.work); +} + /* This function requires the caller holds hdev->req_lock. */ -struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen, - const void *param, u8 event, u32 timeout, - struct sock *sk) +static struct sk_buff *hci_cmd_sync_match(struct hci_dev *hdev, u16 opcode, + u32 plen, const void *param, + u8 event, u32 timeout, struct sock *sk, + hci_req_match_t match) { struct hci_request req; struct sk_buff *skb; @@ -170,19 +214,31 @@ struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen, hci_request_init(&req, hdev); hci_cmd_sync_add(&req, opcode, plen, param, event, sk); + if (match) { + if (req.err) + return ERR_PTR(req.err); + hci_req_match_set(hdev, match); + } WRITE_ONCE(hdev->req_status, HCI_REQ_PEND); err = hci_req_sync_run(&req); - if (err < 0) + if (err < 0 && !match) return ERR_PTR(err); - err = wait_event_interruptible_timeout(hdev->req_wait_q, - READ_ONCE(hdev->req_status) != HCI_REQ_PEND, - timeout); - - if (err == -ERESTARTSYS) - return ERR_PTR(-EINTR); + if (!err) + err = wait_event_interruptible_timeout(hdev->req_wait_q, + READ_ONCE(hdev->req_status) != HCI_REQ_PEND, + timeout); + if (match) + hci_cmd_sync_match_abort(hdev); + if (err == -ERESTARTSYS) { + if (!match) + return ERR_PTR(-EINTR); + err = -EINTR; + } + if (err < 0) + goto done; switch (READ_ONCE(hdev->req_status)) { case HCI_REQ_DONE: @@ -198,6 +254,7 @@ struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen, break; } +done: WRITE_ONCE(hdev->req_status, 0); hdev->req_result = 0; skb = hdev->req_rsp; @@ -218,8 +275,62 @@ struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen, return skb; } + +struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen, + const void *param, u8 event, u32 timeout, + struct sock *sk) +{ + return hci_cmd_sync_match(hdev, opcode, plen, param, event, timeout, sk, + NULL); +} EXPORT_SYMBOL(__hci_cmd_sync_sk); +/* Caller must hold hdev->req_lock. */ +static int __hci_cmd_sync_le_match(struct hci_dev *hdev, u16 opcode, u32 plen, + const void *param, u8 event, u32 timeout, + hci_req_match_t match) +{ + struct sk_buff *skb; + + if (match && hci_opcode_ogf(opcode) != 0x08) + return -EINVAL; + + skb = hci_cmd_sync_match(hdev, opcode, plen, param, event, timeout, NULL, + match); + if (IS_ERR(skb)) + return PTR_ERR(skb) == -ENODATA ? 0 : PTR_ERR(skb); + + kfree_skb(skb); + return 0; +} + +static bool le_conn_update_match(const struct sk_buff *cmd, + const struct sk_buff *event, u8 *status) +{ + struct hci_ev_le_conn_update_complete ev_buf; + struct hci_cp_le_conn_update cp_buf; + const struct hci_ev_le_conn_update_complete *ev; + const struct hci_cp_le_conn_update *cp; + + cp = skb_header_pointer(cmd, HCI_COMMAND_HDR_SIZE, sizeof(cp_buf), + &cp_buf); + ev = skb_header_pointer(event, 0, sizeof(ev_buf), &ev_buf); + if (!cp || !ev || cp->handle != ev->handle) + return false; + + *status = ev->status; + return true; +} + +int hci_le_conn_update_wait_sync(struct hci_dev *hdev, + const struct hci_cp_le_conn_update *cp, + u32 timeout) +{ + return __hci_cmd_sync_le_match(hdev, HCI_OP_LE_CONN_UPDATE, sizeof(*cp), + cp, HCI_EV_LE_CONN_UPDATE_COMPLETE, + timeout, le_conn_update_match); +} + /* This function requires the caller holds hdev->req_lock. */ struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, const void *param, u32 timeout) ^ permalink raw reply related [flat|nested] 8+ messages in thread
* RE: Bluetooth: Load LE connection event length hints through MGMT 2026-12-04 1:03 ` [RFC PATCH v4 1/2] Bluetooth: Allow custom matching of synchronous LE events Kyle Pepper @ 2026-12-04 2:19 ` bluez.test.bot 0 siblings, 0 replies; 8+ messages in thread From: bluez.test.bot @ 2026-12-04 2:19 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/1231251/ ---Test result--- Test Summary: CheckPatch PASS 4.07 seconds VerifyFixes PASS 0.12 seconds VerifySignedoff PASS 0.12 seconds GitLint PASS 0.65 seconds SubjectPrefix PASS 0.23 seconds BuildKernel PASS 30.97 seconds CheckAllWarning PASS 34.92 seconds CheckSparse WARNING 37.64 seconds BuildKernel32 PASS 30.92 seconds CheckKernelLLVM PASS 34.05 seconds TestRunnerSetup PASS 740.60 seconds TestRunner_l2cap-tester PASS 15.02 seconds TestRunner_iso-tester PASS 13.13 seconds TestRunner_bnep-tester PASS 3.18 seconds TestRunner_mgmt-tester PASS 88.83 seconds TestRunner_rfcomm-tester PASS 4.54 seconds TestRunner_sco-tester PASS 5.64 seconds TestRunner_ioctl-tester PASS 4.69 seconds TestRunner_mesh-tester PASS 4.52 seconds TestRunner_smp-tester PASS 4.41 seconds TestRunner_userchan-tester PASS 3.22 seconds TestRunner_6lowpan-tester PASS 4.45 seconds IncrementalBuild PASS 49.02 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/1286 --- Regards, Linux Bluetooth ^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFC PATCH v4 2/2] Bluetooth: Load LE connection event length hints through MGMT 2026-12-04 1:02 ` [RFC PATCH v4 0/2] " Kyle Pepper 2026-12-04 1:03 ` [RFC PATCH v4 1/2] Bluetooth: Allow custom matching of synchronous LE events Kyle Pepper @ 2026-12-04 1:03 ` Kyle Pepper 1 sibling, 0 replies; 8+ messages in thread From: Kyle Pepper @ 2026-12-04 1:03 UTC (permalink / raw) To: linux-bluetooth; +Cc: luiz.dentz, marcel LE connection event length hints are connection parameters. Expose them through a privileged per-peer MGMT command without changing the existing Load Connection Parameters wire format. Store hints for future central connections. For a central link that is up, queue an LE Connection Update using the current connection parameters and commit the hints only after the update succeeds. Zero for both values clears the hints. The controller can choose whether to honor them. Codex assisted with the MGMT handler and CE hint changes. AI assistance: v4 Signed-off-by: Kyle Pepper <cochcoder@proton.me> --- include/net/bluetooth/hci_core.h | 4 + include/net/bluetooth/mgmt.h | 8 ++ net/bluetooth/hci_conn.c | 4 +- net/bluetooth/hci_event.c | 4 +- net/bluetooth/hci_sync.c | 51 +++++++--- net/bluetooth/mgmt.c | 163 +++++++++++++++++++++++++++++++ 6 files changed, 217 insertions(+), 17 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 106fc41a6..67eda3c92 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -786,6 +786,8 @@ struct hci_conn { __u16 le_conn_min_interval; __u16 le_conn_max_interval; __u16 le_conn_interval; + __le16 le_min_ce_len; + __le16 le_max_ce_len; __u16 le_conn_latency; __u16 le_supv_timeout; __u16 le_rate_interval; @@ -885,6 +887,8 @@ struct hci_conn_params { u16 conn_max_interval; u16 conn_latency; u16 supervision_timeout; + __le16 min_ce_len; + __le16 max_ce_len; u16 rate_min_interval; u16 rate_max_interval; diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h index 17bdd6345..786039374 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 2 +#define MGMT_OP_LOAD_CONN_EVENT_LEN 0x005D +struct mgmt_cp_load_conn_event_len { + struct mgmt_addr_info addr; + __le16 min_ce_len; + __le16 max_ce_len; +} __packed; +#define MGMT_LOAD_CONN_EVENT_LEN_SIZE 11 + #define MGMT_EV_CMD_COMPLETE 0x0001 struct mgmt_ev_cmd_complete { __le16 opcode; diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index f37459d41..0a01912f5 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 = conn->le_min_ce_len; + cp.max_ce_len = conn->le_max_ce_len; timeout = conn->conn_timeout; hci_dev_unlock(hdev); diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index a6c4fb486..e490faa5f 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 = hcon->le_min_ce_len; + cp.max_ce_len = 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 ef1009632..e1f3abcf5 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -7644,7 +7644,8 @@ static int hci_le_directed_advertising_sync(struct hci_dev *hdev, } static void set_ext_conn_params(struct hci_conn *conn, - struct hci_cp_le_ext_conn_param *p) + struct hci_cp_le_ext_conn_param *p, + __le16 min_ce_len, __le16 max_ce_len) { struct hci_dev *hdev = conn->hdev; @@ -7656,12 +7657,13 @@ static void set_ext_conn_params(struct hci_conn *conn, p->conn_interval_max = cpu_to_le16(conn->le_conn_max_interval); p->conn_latency = cpu_to_le16(conn->le_conn_latency); p->supervision_timeout = cpu_to_le16(conn->le_supv_timeout); - p->min_ce_len = cpu_to_le16(0x0000); - p->max_ce_len = cpu_to_le16(0x0000); + p->min_ce_len = min_ce_len; + p->max_ce_len = max_ce_len; } static int hci_le_ext_create_conn_sync(struct hci_dev *hdev, - struct hci_conn *conn, u8 own_addr_type) + struct hci_conn *conn, u8 own_addr_type, + __le16 min_ce_len, __le16 max_ce_len) { struct hci_cp_le_ext_create_conn *cp; struct hci_cp_le_ext_conn_param *p; @@ -7682,7 +7684,7 @@ static int hci_le_ext_create_conn_sync(struct hci_dev *hdev, if (scan_1m(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_1M || conn->le_adv_sec_phy == HCI_ADV_PHY_1M)) { cp->phys |= LE_SCAN_PHY_1M; - set_ext_conn_params(conn, p); + set_ext_conn_params(conn, p, min_ce_len, max_ce_len); p++; plen += sizeof(*p); @@ -7691,7 +7693,7 @@ static int hci_le_ext_create_conn_sync(struct hci_dev *hdev, if (scan_2m(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_2M || conn->le_adv_sec_phy == HCI_ADV_PHY_2M)) { cp->phys |= LE_SCAN_PHY_2M; - set_ext_conn_params(conn, p); + set_ext_conn_params(conn, p, min_ce_len, max_ce_len); p++; plen += sizeof(*p); @@ -7700,7 +7702,7 @@ static int hci_le_ext_create_conn_sync(struct hci_dev *hdev, if (scan_coded(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_CODED || conn->le_adv_sec_phy == HCI_ADV_PHY_CODED)) { cp->phys |= LE_SCAN_PHY_CODED; - set_ext_conn_params(conn, p); + set_ext_conn_params(conn, p, min_ce_len, max_ce_len); plen += sizeof(*p); } @@ -7715,6 +7717,8 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data) { struct hci_cp_le_create_conn cp; struct hci_conn_params *params; + struct smp_irk *irk; + __le16 min_ce_len, max_ce_len; u8 own_addr_type; int err; struct hci_conn *conn = data; @@ -7754,19 +7758,32 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data) hci_dev_lock(hdev); - params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); + /* Parameters are keyed by identity, not the RPA used to connect. */ + irk = hci_get_irk(hdev, &conn->dst, conn->dst_type); + if (irk) + params = hci_conn_params_lookup(hdev, &irk->bdaddr, + irk->addr_type); + else + params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); if (params) { conn->le_conn_min_interval = params->conn_min_interval; conn->le_conn_max_interval = params->conn_max_interval; conn->le_conn_latency = params->conn_latency; conn->le_supv_timeout = params->supervision_timeout; + conn->le_min_ce_len = params->min_ce_len; + conn->le_max_ce_len = params->max_ce_len; } else { conn->le_conn_min_interval = hdev->le_conn_min_interval; conn->le_conn_max_interval = hdev->le_conn_max_interval; conn->le_conn_latency = hdev->le_conn_latency; conn->le_supv_timeout = hdev->le_supv_timeout; + conn->le_min_ce_len = 0; + conn->le_max_ce_len = 0; } + min_ce_len = conn->le_min_ce_len; + max_ce_len = conn->le_max_ce_len; + hci_dev_unlock(hdev); /* If controller is scanning, we stop it since some controllers are @@ -7795,7 +7812,8 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data) /* Send command LE Extended Create Connection if supported */ if (use_ext_conn(hdev)) { - err = hci_le_ext_create_conn_sync(hdev, conn, own_addr_type); + err = hci_le_ext_create_conn_sync(hdev, conn, own_addr_type, + min_ce_len, max_ce_len); goto done; } @@ -7811,8 +7829,8 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data) cp.conn_interval_max = cpu_to_le16(conn->le_conn_max_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(0x0000); - cp.max_ce_len = cpu_to_le16(0x0000); + cp.min_ce_len = min_ce_len; + cp.max_ce_len = max_ce_len; /* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 2261: * @@ -8299,14 +8317,21 @@ 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 = conn->le_min_ce_len; + cp.max_ce_len = 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/mgmt.c b/net/bluetooth/mgmt.c index 01969ab57..6681ee301 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -130,6 +130,7 @@ static const u16 mgmt_commands[] = { MGMT_OP_MESH_SEND, MGMT_OP_MESH_SEND_CANCEL, MGMT_OP_HCI_CMD_SYNC, + MGMT_OP_LOAD_CONN_EVENT_LEN, }; static const u16 mgmt_events[] = { @@ -8590,6 +8591,167 @@ static int load_conn_subrate(struct sock *sk, struct hci_dev *hdev, void *data, NULL, 0); } +static int conn_event_len_sync(struct hci_dev *hdev, void *data) +{ + struct mgmt_pending_cmd *cmd = data; + struct mgmt_cp_load_conn_event_len *param = cmd->param; + struct hci_conn *conn = cmd->user_data; + struct hci_cp_le_conn_update cp = {}; + u32 timeout; + + hci_dev_lock(hdev); + if (!hci_conn_valid(hdev, conn) || + (conn->state != BT_CONNECTED && conn->state != BT_CONFIG)) { + hci_dev_unlock(hdev); + return -ENOTCONN; + } + + /* A legacy update would replace non-legacy rate parameters. */ + if (conn->le_subrate > 1 || + (conn->le_rate_interval && + (conn->le_rate_interval != conn->le_conn_interval * 10 || + conn->le_rate_latency != conn->le_conn_latency || + conn->le_rate_supv_timeout != conn->le_supv_timeout))) { + hci_dev_unlock(hdev); + return -EOPNOTSUPP; + } + + cp.handle = cpu_to_le16(conn->handle); + cp.conn_interval_min = cpu_to_le16(conn->le_conn_interval); + cp.conn_interval_max = cp.conn_interval_min; + cp.conn_latency = cpu_to_le16(conn->le_conn_latency); + cp.supervision_timeout = cpu_to_le16(conn->le_supv_timeout); + cp.min_ce_len = param->min_ce_len; + cp.max_ce_len = param->max_ce_len; + timeout = conn->conn_timeout ?: HCI_CMD_TIMEOUT; + hci_dev_unlock(hdev); + + return hci_le_conn_update_wait_sync(hdev, &cp, timeout); +} + +/* Caller holds hdev->lock. Clearing an unknown peer is a no-op. */ +static int conn_event_len_commit(struct hci_dev *hdev, struct hci_conn *conn, + struct mgmt_cp_load_conn_event_len *cp, u8 type) +{ + struct hci_conn_params *params; + + if (conn && hci_conn_valid(hdev, conn)) { + conn->le_min_ce_len = cp->min_ce_len; + conn->le_max_ce_len = cp->max_ce_len; + } + + params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, type); + if (!params) { + if (!cp->min_ce_len && !cp->max_ce_len) + return 0; + params = hci_conn_params_add(hdev, &cp->addr.bdaddr, type); + if (!params) + return -ENOMEM; + } + + params->min_ce_len = cp->min_ce_len; + params->max_ce_len = cp->max_ce_len; + return 0; +} + +static u8 conn_event_len_status(int err) +{ + switch (err) { + case -ETIMEDOUT: + return MGMT_STATUS_TIMEOUT; + case -ENOTCONN: + return MGMT_STATUS_NOT_CONNECTED; + default: + return mgmt_status(err); + } +} + +static void conn_event_len_complete(struct hci_dev *hdev, void *data, int err) +{ + struct mgmt_pending_cmd *cmd = data; + struct mgmt_cp_load_conn_event_len *cp = cmd->param; + struct hci_conn *conn = cmd->user_data; + + if (!err) { + hci_dev_lock(hdev); + if (conn_event_len_commit(hdev, conn, cp, + le_addr_type(cp->addr.type))) + bt_dev_warn(hdev, "failed to store CE length hints"); + hci_dev_unlock(hdev); + } + + mgmt_cmd_complete(cmd->sk, hdev->id, cmd->opcode, + conn_event_len_status(err), NULL, 0); + hci_conn_put(conn); + mgmt_pending_free(cmd); +} + +static int load_conn_event_len(struct sock *sk, struct hci_dev *hdev, + void *data, u16 len) +{ + struct mgmt_cp_load_conn_event_len *cp = data; + struct hci_conn *conn; + u8 status; + u8 type; + + if (!lmp_le_capable(hdev)) + return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_EVENT_LEN, + MGMT_STATUS_NOT_SUPPORTED); + + if (cp->addr.type != BDADDR_LE_PUBLIC && cp->addr.type != BDADDR_LE_RANDOM) + goto invalid; + type = le_addr_type(cp->addr.type); + + if (!bacmp(&cp->addr.bdaddr, BDADDR_ANY) || + le16_to_cpu(cp->min_ce_len) > le16_to_cpu(cp->max_ce_len)) + goto invalid; + + hci_dev_lock(hdev); + conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, type); + if (conn && conn->role == HCI_ROLE_MASTER && conn->state == BT_CONNECT) { + status = MGMT_STATUS_BUSY; + goto done; + } + + if (conn && conn->role == HCI_ROLE_MASTER && + (conn->state == BT_CONFIG || conn->state == BT_CONNECTED)) { + struct mgmt_pending_cmd *cmd; + int err; + + cmd = mgmt_pending_new(sk, MGMT_OP_LOAD_CONN_EVENT_LEN, hdev, + data, len); + if (!cmd) { + status = MGMT_STATUS_NO_RESOURCES; + goto done; + } + + cmd->user_data = hci_conn_get(conn); + err = hci_cmd_sync_queue(hdev, conn_event_len_sync, cmd, + conn_event_len_complete); + if (err) { + hci_conn_put(conn); + mgmt_pending_free(cmd); + status = mgmt_status(err); + goto done; + } + + hci_dev_unlock(hdev); + return 0; + } + + status = conn_event_len_commit(hdev, NULL, cp, type) ? + MGMT_STATUS_NO_RESOURCES : MGMT_STATUS_SUCCESS; + +done: + hci_dev_unlock(hdev); + return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_CONN_EVENT_LEN, + status, NULL, 0); + +invalid: + return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_EVENT_LEN, + MGMT_STATUS_INVALID_PARAMS); +} + static int set_external_config(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) { @@ -10058,6 +10220,7 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { { mgmt_hci_cmd_sync, MGMT_HCI_CMD_SYNC_SIZE, HCI_MGMT_VAR_LEN }, { load_conn_subrate, MGMT_LOAD_CONN_SUBRATE_SIZE, HCI_MGMT_VAR_LEN }, + { load_conn_event_len, MGMT_LOAD_CONN_EVENT_LEN_SIZE }, }; void mgmt_index_added(struct hci_dev *hdev) ^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-12-04 2:19 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-03 18:41 [RFC PATCH v3 0/2] Bluetooth: Load LE connection event length hints through MGMT Kyle Pepper 2026-12-03 18:41 ` [RFC PATCH v3 1/2] Bluetooth: Allow custom matching of synchronous LE events Kyle Pepper 2026-12-04 2:10 ` Bluetooth: Load LE connection event length hints through MGMT bluez.test.bot 2026-12-03 18:41 ` [RFC PATCH v3 2/2] " Kyle Pepper 2026-12-04 1:02 ` [RFC PATCH v4 0/2] " Kyle Pepper 2026-12-04 1:03 ` [RFC PATCH v4 1/2] Bluetooth: Allow custom matching of synchronous LE events Kyle Pepper 2026-12-04 2:19 ` Bluetooth: Load LE connection event length hints through MGMT bluez.test.bot 2026-12-04 1:03 ` [RFC PATCH v4 2/2] " Kyle Pepper
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox