From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796336066; b=G+jC88E7tFMEqjK5QE6EatJYoUH44LFqlSIVW1RbTWIbnLE3yGRtXyxD0apIK308CKZl VrApA/0iOxlMFS2q/YRTnuQXLlPdN/FsYS+t6C9rqsomlcAdUWth7RNCtv428q5nz/T8B 1iOHGS/2gHYO6f0+AyWvO0OfM13ZlalDG1jMoG9tlQvtVbkMj3hdwz2/ExGjD0Uo7zyoM Ap5S9tbCIYOn9w90JwOMotRJV5ghzehfkxxsd3duXEG8KJ1qrQeNtOalJDePPZvtDBeah C1vwk3Q2O2EIJ5I9NR0UsO0VpY7k4VT6T4BCkObqjGq0TgintJZUz3FlV5bAJN303MA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796336066; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=6yB33Aj9v8pPc6MQ79BkufkmL9Ksk5WIXxnbkhOOrSg=; b=n8QoMG8u0UvawfYKi8WiogFRklcxFa6osXJdV97y9OguY3mUuhnaqNqQUn2yT+u0/unw dwhEKPAec137JR3CtGX1dZ90moQOyP36AIfjn8XTj8zvp9zYgGFLcu+o58Ez/WO/NT5QU zMctKcjXnYn3s+/TznAONyLDrZcXoe8OnV3D8URsFGO0nnnzzojxIzpnN8HhkYItc+uzD ie78VxkDg1mg5PaZDKJZbPya7QCaw8xOD60bXjWGVV3Lh2WBhP/WxkPRpqJ7HNIde4wgD FzOjprOG0DtdxYHu5J2DiMLp86oYCsaWa3W/ik/LMMt6tGUN5ePuDZipUWkhyBS1PQw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="dY/wPVdy"; arc=none smtp.remote-ip=209.85.128.46 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 718BE606A335 for ; Thu, 3 Dec 2026 22:14:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 718BE606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dY/wPVdy Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4bb5e3cbf45so231445e9.1 for ; Thu, 03 Dec 2026 14:14:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796336064; x=1796940864; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6yB33Aj9v8pPc6MQ79BkufkmL9Ksk5WIXxnbkhOOrSg=; b=dY/wPVdyGEJc+3bYutO6q8ftxzYCJPXNYBD/AcDaNCRf2zs7Vjuz2sYBFv1EOeCCj/ pr7OBAqcIP2lLnAcAIDuY0T++FZrU5PjzxIJ8C6JRHYpagkkwVy2YTel8yuEarTskOh1 WH0cCZHve+Tys1QPXPdkJOsIT186dTEpaSpZ3MLkGdWXK7+wSFhrQlZfypTD4GC/qrSU 6cCqZF+gMzzb9RutJvxPrlO8pTwfTbDHGaPtQDXI7p6tW527vTBUWkDFdP9FOzD/9NCm 0he5f4RnvnyZCtYVoWSply79nqqljZpICATNYkizKoxg1vyh2gplAjUaH9tKz6VBo1a2 MxLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796336064; x=1796940864; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=6yB33Aj9v8pPc6MQ79BkufkmL9Ksk5WIXxnbkhOOrSg=; b=NkStlfZepeMRSJ/IFbGntu2c/SxqIb6Yf7LmYGZg25gQ82pCLrx9DoHJGrFqweo9HT WU+UsnWQvYGB9lrRzIMm/TOkKEpq7Gq+pnxFsCDc4mOz854q0ATCTIIXdF97XRZI3dwO Jsr8su1haodteo7uupAxNs4WLXnXAmqA4UfNruGY7b0hbLyYgbVNjrMBBK8o3M/rI6QA DGF+kYHJ1FuGFiMd9MfoAam6GlWR2dEZy34CfPvs22AT8p+6HshZ7LPgDpgaghaoNL28 loycNTirnIEyJ2aw6G+sBUU6UJb+k3dWP20p8B1zKdMuGQsMyJ5yJYmChrotwJKBJMo2 VRIg== X-Gm-Message-State: APuU4Z9nmA6cj3fl/55gkOlAZMSnMWY21PcTIG8e81NYHMAxEWxebGN3 txjtQjBEk3Meh0lus1Mma7cPr8RCTwuYCewXDISH43bBMgybqbRRBLYqTRadLUb4 X-Gm-Gg: AZFdTZdpQoZuvacmFuuuaIzYIadq8XErARy3W32TvA4aBAymURnGzq1KQHou+LgVp6s Uk3rs0GPf+11Hd8O8+k7bEhflqugt8RvmDk3MldzlP3cQXbxml/8i3LIJEN59GAyvk7FeDYV17O xlHjxyV+br6j1jr3G+Wi9oZi3z8Igx696PH9Sp4B+z1LZRO5vqEwqy8pI8e1tCkjfsh29Zvt7Cm /X0cjP4GfM3Tr455kXnZIdCtDBQOGyMno+cSWMIaH/k+Oke4GkqFHZCVkRz84A3DKKQIOCNOphS Ek5OaRoTrDOkkpgUMU/Jn8456B4khdqfA9i5uYVoVY44N8kIE+snioYv5oQ6qS6oipLm4OxcpYp 50nPw8mf8mAlTMaSWZ4+xm+CGShQv42Nb/1bfcecZy+SqFE/ORBMtN7UMryBi6HRsO7uPXG9Y4a 1M/skiKH3Vr0Pu2bv0iwokpIyJNkYhvK3fwVO/Qp7bQlDYFIiTLWPM6pw3jbSank6WVaDbzTcei YFyCL3eU4YG5+xiVads/cgEGWY7C8tu3JxPV5Koo9XIR14lW4wfYqDb3D1HNgJ6CI+qbhj/DDy9 H8ys5H3Q014ylAPzwehIo3rwnK4SoOl5ScO7X07NoOlVrusF X-Received: by 2002:a05:600c:621b:b0:4bb:b631:92e3 with SMTP id 5b1f17b1804b1-4bbeb850ed3mr555095e9.2.1796336064409; Thu, 03 Dec 2026 14:14:24 -0800 (PST) Received: from schinder.fritz.box ([2001:9e8:b39a:7900:a13b:fe74:8c9c:c788]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe00df154sm117266225e9.14.2026.12.03.14.14.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 14:14:24 -0800 (PST) From: Roland Schober To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, Roland Schober Subject: [RFC PATCH v2 6/6] Bluetooth: MGMT: Add PAwR subevent data and response reports Date: Thu, 3 Dec 2026 23:14:05 +0100 Message-ID: <20261203221405.682222-7-rolandschober1968@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261203221405.682222-1-rolandschober1968@gmail.com> References: <20261203221405.682222-1-rolandschober1968@gmail.com> 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-Transfer-Encoding: 8bit Complete the advertiser side of Periodic Advertising with Responses (PAwR) over MGMT: PA Subevent Data Request event the controller asks for the data of a range of subevents Set PA Subevent Data command user space answers with that data PA Response Report event the responses received in the response slots of a subevent The LE events behind the two MGMT events are enabled if the controller supports the PAwR advertiser feature, and are forwarded for instances with subevents only. The controller wants the subevent data within its lead time, a few tens of milliseconds before the subevent. Set PA Subevent Data is therefore sent with hci_send_cmd() and answered from the Command Complete handler, not queued with hci_cmd_sync_queue(), where it would wait behind sequences which block for an event, such as creating a connection. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Roland Schober --- include/net/bluetooth/hci_core.h | 6 ++ include/net/bluetooth/mgmt.h | 49 ++++++++++ net/bluetooth/hci_event.c | 90 +++++++++++++++++ net/bluetooth/hci_sync.c | 5 + net/bluetooth/mgmt.c | 162 +++++++++++++++++++++++++++++++ 5 files changed, 312 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 117408645b9b..37ac912fbb85 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -2661,6 +2661,12 @@ void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle, bdaddr_t *bdaddr, u8 addr_type); void mgmt_conn_subrate_notify(struct hci_dev *hdev, struct hci_conn *conn, u8 status); +void mgmt_pa_subevent_data_request(struct hci_dev *hdev, u8 instance, + u8 subevent_start, u8 subevent_data_count); +void mgmt_set_pa_subevent_data_complete(struct hci_dev *hdev, u8 status); +void mgmt_pa_response_report(struct hci_dev *hdev, u8 instance, u8 subevent, + u8 tx_status, u8 num_responses, + const void *responses, u16 len); int hci_abort_conn(struct hci_conn *conn, u8 reason); void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency, diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h index a46e87a9152c..b85ff94e518c 100644 --- a/include/net/bluetooth/mgmt.h +++ b/include/net/bluetooth/mgmt.h @@ -952,6 +952,28 @@ struct mgmt_rp_add_periodic_adv_data { __u8 instance; } __packed; +struct mgmt_pa_subevent_data { + __u8 subevent; + __u8 response_slot_start; + __u8 response_slot_count; + __u8 data_len; + __u8 data[] __counted_by(data_len); +} __packed; + +/* The answer to MGMT_EV_PA_SUBEVENT_DATA_REQUEST: num_subevents entries of + * struct mgmt_pa_subevent_data. + */ +#define MGMT_OP_SET_PA_SUBEVENT_DATA 0x005F +struct mgmt_cp_set_pa_subevent_data { + __u8 instance; + __u8 num_subevents; + __u8 subevents[]; +} __packed; +#define MGMT_SET_PA_SUBEVENT_DATA_SIZE 2 +struct mgmt_rp_set_pa_subevent_data { + __u8 instance; +} __packed; + #define MGMT_EV_CMD_COMPLETE 0x0001 struct mgmt_ev_cmd_complete { __le16 opcode; @@ -1276,3 +1298,30 @@ struct mgmt_ev_security_level_changed { __u8 tlv_length; __u8 tlv_data[] __counted_by(tlv_length); } __packed; + +#define MGMT_EV_PA_SUBEVENT_DATA_REQUEST 0x0035 +struct mgmt_ev_pa_subevent_data_request { + __u8 instance; + __u8 subevent_start; + __u8 subevent_data_count; +} __packed; + +struct mgmt_pa_response { + __s8 tx_power; + __s8 rssi; + __u8 cte_type; + __u8 response_slot; + __u8 data_status; + __u8 data_len; + __u8 data[] __counted_by(data_len); +} __packed; + +/* num_responses entries of struct mgmt_pa_response */ +#define MGMT_EV_PA_RESPONSE_REPORT 0x0036 +struct mgmt_ev_pa_response_report { + __u8 instance; + __u8 subevent; + __u8 tx_status; + __u8 num_responses; + __u8 responses[]; +} __packed; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 8f4a9c261985..6eec5a7f1f69 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4608,6 +4608,20 @@ static u8 hci_cc_le_set_per_adv_enable(struct hci_dev *hdev, void *data, return rp->status; } +static u8 hci_cc_le_set_per_adv_subevent_data(struct hci_dev *hdev, void *data, + struct sk_buff *skb) +{ + struct hci_ev_status *rp = data; + + bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); + + hci_dev_lock(hdev); + mgmt_set_pa_subevent_data_complete(hdev, rp->status); + hci_dev_unlock(hdev); + + return rp->status; +} + #define HCI_CC_VL(_op, _func, _min, _max) \ { \ .op = _op, \ @@ -4784,6 +4798,10 @@ static const struct hci_cc { HCI_CC_STATUS(HCI_OP_LE_SET_PER_ADV_PARAMS, hci_cc_set_per_adv_param), HCI_CC_STATUS(HCI_OP_LE_SET_PER_ADV_ENABLE, hci_cc_le_set_per_adv_enable), + /* Status and advertising handle */ + HCI_CC_VL(HCI_OP_LE_SET_PER_ADV_SUBEVENT_DATA, + hci_cc_le_set_per_adv_subevent_data, + sizeof(struct hci_ev_status), HCI_MAX_CC_PLEN), HCI_CC(HCI_OP_LE_READ_TRANSMIT_POWER, hci_cc_le_read_transmit_power, sizeof(struct hci_rp_le_read_transmit_power)), HCI_CC_STATUS(HCI_OP_LE_SET_PRIVACY_MODE, hci_cc_le_set_privacy_mode), @@ -8170,6 +8188,69 @@ static void hci_le_big_info_adv_report_evt(struct hci_dev *hdev, void *data, hci_dev_unlock(hdev); } +static void hci_le_per_adv_subevent_data_req_evt(struct hci_dev *hdev, + void *data, + struct sk_buff *skb) +{ + struct hci_ev_le_per_adv_subevent_data_req *ev = data; + struct adv_info *adv; + + bt_dev_dbg(hdev, "handle 0x%2.2x start %u count %u", ev->handle, + ev->subevent_start, ev->subevent_data_count); + + hci_dev_lock(hdev); + + adv = hci_le_ext_adv_owner(hdev, ev->handle); + if (adv && adv->num_subevents) + mgmt_pa_subevent_data_request(hdev, adv->instance, + ev->subevent_start, + ev->subevent_data_count); + + hci_dev_unlock(hdev); +} + +static void hci_le_per_adv_response_report_evt(struct hci_dev *hdev, + void *data, struct sk_buff *skb) +{ + struct hci_ev_le_per_adv_response_report *ev = data; + struct hci_le_per_adv_response *rsp; + struct adv_info *adv; + void *responses = skb->data; + u16 len = skb->len; + u8 i; + + bt_dev_dbg(hdev, "handle 0x%2.2x subevent %u num %u", ev->handle, + ev->subevent, ev->num_responses); + + /* The responses go to user space as they are: check that they are + * all there. + */ + for (i = 0; i < ev->num_responses; i++) { + rsp = hci_le_ev_skb_pull(hdev, skb, + HCI_EV_LE_PER_ADV_RESPONSE_REPORT, + sizeof(*rsp)); + if (!rsp) + return; + + if (!hci_le_ev_skb_pull(hdev, skb, + HCI_EV_LE_PER_ADV_RESPONSE_REPORT, + rsp->data_len)) + return; + } + + len -= skb->len; + + hci_dev_lock(hdev); + + adv = hci_le_ext_adv_owner(hdev, ev->handle); + if (adv && adv->num_subevents) + mgmt_pa_response_report(hdev, adv->instance, ev->subevent, + ev->tx_status, ev->num_responses, + responses, len); + + hci_dev_unlock(hdev); +} + static void hci_le_read_all_remote_features_evt(struct hci_dev *hdev, void *data, struct sk_buff *skb) { @@ -8479,6 +8560,15 @@ static const struct hci_le_ev { hci_le_big_info_adv_report_evt, sizeof(struct hci_evt_le_big_info_adv_report), HCI_MAX_LE_SUBEVT_PLEN), + /* [0x27 = HCI_EV_LE_PER_ADV_SUBEVENT_DATA_REQ] */ + HCI_LE_EV(HCI_EV_LE_PER_ADV_SUBEVENT_DATA_REQ, + hci_le_per_adv_subevent_data_req_evt, + sizeof(struct hci_ev_le_per_adv_subevent_data_req)), + /* [0x28 = HCI_EV_LE_PER_ADV_RESPONSE_REPORT] */ + HCI_LE_EV_VL(HCI_EV_LE_PER_ADV_RESPONSE_REPORT, + hci_le_per_adv_response_report_evt, + sizeof(struct hci_ev_le_per_adv_response_report), + HCI_MAX_LE_SUBEVT_PLEN), /* [0x2b = HCI_EVT_LE_ALL_REMOTE_FEATURES_COMPLETE] */ HCI_LE_EV_VL(HCI_EVT_LE_ALL_REMOTE_FEATURES_COMPLETE, hci_le_read_all_remote_features_evt, diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 05151cf6f413..71005596f7df 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5099,6 +5099,11 @@ static int hci_le_set_event_mask_sync(struct hci_dev *hdev) if (ll_ext_feature_capable(hdev)) events[5] |= BIT(2); + if (pawr_adv_capable(hdev)) { + events[4] |= 0x40; /* LE PA Subevent Data Request */ + events[4] |= 0x80; /* LE PA Response Report */ + } + if (le_cs_capable(hdev)) { /* Channel Sounding events */ events[5] |= 0x08; /* LE CS Read Remote Supported Cap Complete event */ diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index c0e655a189e0..495b3e28e577 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -132,6 +132,7 @@ static const u16 mgmt_commands[] = { MGMT_OP_HCI_CMD_SYNC, MGMT_OP_ADD_PERIODIC_ADV_PARAMS, MGMT_OP_ADD_PERIODIC_ADV_DATA, + MGMT_OP_SET_PA_SUBEVENT_DATA, }; static const u16 mgmt_events[] = { @@ -180,6 +181,8 @@ static const u16 mgmt_events[] = { MGMT_EV_ADV_MONITOR_DEVICE_FOUND, MGMT_EV_ADV_MONITOR_DEVICE_LOST, MGMT_EV_SECURITY_LEVEL_CHANGED, + MGMT_EV_PA_SUBEVENT_DATA_REQUEST, + MGMT_EV_PA_RESPONSE_REPORT, }; static const u16 mgmt_untrusted_commands[] = { @@ -10014,6 +10017,122 @@ static int add_periodic_adv_data(struct sock *sk, struct hci_dev *hdev, return err; } +/* The controller's answer to LE Set Periodic Advertising Subevent Data. The + * commands are answered in the order they were sent. + */ +void mgmt_set_pa_subevent_data_complete(struct hci_dev *hdev, u8 status) +{ + struct mgmt_cp_set_pa_subevent_data *cp; + struct mgmt_rp_set_pa_subevent_data rp; + struct mgmt_pending_cmd *cmd; + + cmd = pending_find(MGMT_OP_SET_PA_SUBEVENT_DATA, hdev); + if (!cmd) + return; + + cp = cmd->param; + + if (status) { + mgmt_cmd_status(cmd->sk, hdev->id, cmd->opcode, + mgmt_status(status)); + } else { + rp.instance = cp->instance; + mgmt_cmd_complete(cmd->sk, hdev->id, cmd->opcode, + MGMT_STATUS_SUCCESS, &rp, sizeof(rp)); + } + + mgmt_pending_remove(cmd); +} + +static int set_pa_subevent_data(struct sock *sk, struct hci_dev *hdev, + void *data, u16 data_len) +{ + DEFINE_RAW_FLEX(struct hci_cp_le_set_per_adv_subevent_data, hci_cp, + subevents, HCI_MAX_PER_ADV_SUBEVENT_DATA_LEN); + struct mgmt_cp_set_pa_subevent_data *cp = data; + struct mgmt_pa_subevent_data *subevent; + struct mgmt_pending_cmd *cmd; + struct adv_info *adv; + u16 len = data_len - sizeof(*cp); + u16 left = len; + u8 *ptr = cp->subevents; + int err; + u8 i; + + bt_dev_dbg(hdev, "sock %p", sk); + + BUILD_BUG_ON(sizeof(struct mgmt_pa_subevent_data) != + sizeof(struct hci_le_per_adv_subevent_data)); + + /* One HCI command takes it all, or nothing is sent */ + if (left > HCI_MAX_PER_ADV_SUBEVENT_DATA_LEN) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_PA_SUBEVENT_DATA, + MGMT_STATUS_INVALID_PARAMS); + + for (i = 0; i < cp->num_subevents; i++) { + subevent = (void *)ptr; + + if (left < sizeof(*subevent) || + left < sizeof(*subevent) + subevent->data_len) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_PA_SUBEVENT_DATA, + MGMT_STATUS_INVALID_PARAMS); + + ptr += sizeof(*subevent) + subevent->data_len; + left -= sizeof(*subevent) + subevent->data_len; + } + + if (!cp->num_subevents || left) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_PA_SUBEVENT_DATA, + MGMT_STATUS_INVALID_PARAMS); + + hci_dev_lock(hdev); + + if (!hdev_is_powered(hdev)) { + err = mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_PA_SUBEVENT_DATA, + MGMT_STATUS_REJECTED); + goto unlock; + } + + adv = hci_find_adv_instance(hdev, cp->instance); + if (!adv || !adv->periodic || !adv->num_subevents) { + err = mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_PA_SUBEVENT_DATA, + MGMT_STATUS_INVALID_PARAMS); + goto unlock; + } + + cmd = mgmt_pending_add(sk, MGMT_OP_SET_PA_SUBEVENT_DATA, hdev, data, + data_len); + if (!cmd) { + err = -ENOMEM; + goto unlock; + } + + /* struct mgmt_pa_subevent_data has the layout of the HCI one */ + hci_cp->handle = adv->handle; + hci_cp->num_subevents = cp->num_subevents; + memcpy(hci_cp->subevents, cp->subevents, len); + + /* The controller wants the data within its lead time, a few tens of + * milliseconds. The command is therefore not queued with + * hci_cmd_sync_queue(): it would wait behind sequences which block + * for an event, such as creating a connection. + */ + err = hci_send_cmd(hdev, HCI_OP_LE_SET_PER_ADV_SUBEVENT_DATA, + struct_size(hci_cp, subevents, len), hci_cp); + if (err < 0) + mgmt_pending_remove(cmd); + +unlock: + hci_dev_unlock(hdev); + + return err; +} + static void remove_advertising_complete(struct hci_dev *hdev, void *data, int err) { @@ -10278,6 +10397,8 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { { add_periodic_adv_params, MGMT_ADD_PERIODIC_ADV_PARAMS_SIZE }, { add_periodic_adv_data, MGMT_ADD_PERIODIC_ADV_DATA_SIZE, HCI_MGMT_VAR_LEN }, + { set_pa_subevent_data, MGMT_SET_PA_SUBEVENT_DATA_SIZE, + HCI_MGMT_VAR_LEN }, }; void mgmt_index_added(struct hci_dev *hdev) @@ -11131,6 +11252,47 @@ void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle, NULL); } +void mgmt_pa_subevent_data_request(struct hci_dev *hdev, u8 instance, + u8 subevent_start, u8 subevent_data_count) +{ + struct mgmt_ev_pa_subevent_data_request ev; + + ev.instance = instance; + ev.subevent_start = subevent_start; + ev.subevent_data_count = subevent_data_count; + + mgmt_event(MGMT_EV_PA_SUBEVENT_DATA_REQUEST, hdev, &ev, sizeof(ev), + NULL); +} + +/* responses: num_responses entries of struct hci_le_per_adv_response, which + * has the layout of struct mgmt_pa_response, len octets in total. + */ +void mgmt_pa_response_report(struct hci_dev *hdev, u8 instance, u8 subevent, + u8 tx_status, u8 num_responses, + const void *responses, u16 len) +{ + struct mgmt_ev_pa_response_report *ev; + struct sk_buff *skb; + + BUILD_BUG_ON(sizeof(struct mgmt_pa_response) != + sizeof(struct hci_le_per_adv_response)); + + skb = mgmt_alloc_skb(hdev, MGMT_EV_PA_RESPONSE_REPORT, + sizeof(*ev) + len); + if (!skb) + return; + + ev = skb_put(skb, sizeof(*ev)); + ev->instance = instance; + ev->subevent = subevent; + ev->tx_status = tx_status; + ev->num_responses = num_responses; + skb_put_data(skb, responses, len); + + mgmt_event_skb(skb, NULL); +} + static void mgmt_send_adv_monitor_device_found(struct hci_dev *hdev, struct sk_buff *skb, struct sock *skip_sk, -- 2.47.3