Linux bluetooth development
 help / color / mirror / Atom feed
* [RFC PATCH 0/5] Bluetooth: Periodic advertising and PAwR over MGMT
@ 2026-11-27  8:53 Roland Schober
  2026-11-27  8:53 ` [RFC PATCH 1/5] Bluetooth: hci: Add Periodic Advertising with Responses definitions Roland Schober
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Roland Schober @ 2026-11-27  8:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, marcel, Roland Schober

Hi Luiz,

a few weeks ago I asked on this list, from my work address, whether
Periodic Advertising with Responses (PAwR) is planned, for a gateway
which serves battery powered displays like an ESL access point. You
suggested to start with PA and PAwR in MGMT, then the D-Bus API, with
emulator support so that it can be tested automatically.

This is the first step: periodic advertising and the advertiser side
of PAwR over MGMT, with emulator support and mgmt-tester cases in the
BlueZ series. I send it as RFC to get your view on the interface
before I go on with the responder side of the emulator and the D-Bus
API.

The interface (patches 3 to 5):

  Add Periodic Advertising Parameters (0x005d)
      Makes an instance created with Add Extended Advertising Parameters
      periodic, before Add Extended Advertising Data enables it. With a
      number of subevents it is PAwR, without it is plain periodic
      advertising.
  Add Periodic Advertising Data (0x005e)
      The data of a plain periodic advertising train.
  Periodic Advertising Subevent Data Request event (0x0035)
      The controller asks for the data of a range of subevents.
  Set Periodic Advertising Subevent Data (0x005f)
      The answer: the data of one or more subevents, in one HCI command.
  Periodic Advertising Response Report event (0x0036)
      The responses received in the response slots of a subevent.

The parameters and the entries are those of the HCI commands and
events, in their units; the advertising handle is replaced by the
instance.

Questions:

1. New commands, or flags and parameters added to Add Extended
   Advertising Parameters and Add Extended Advertising Data? I chose
   commands of their own because the existing ones have no room for
   the parameters, and an instance can then become periodic without a
   second way to create it.

2. Set Periodic Advertising Subevent Data is sent with hci_send_cmd()
   and answered from the Command Complete handler, as the PIN code and
   user confirmation replies are. Queued with hci_cmd_sync_queue() it
   waited behind the connection setup, and the controller refused the
   data as too late: it wants the data within its lead time, 40 to 50 ms
   on the controller I tested with. Is this acceptable, or is there a
   better way to send a command which must not wait?

3. The kernel does not check that the subevents of the answer are the
   requested ones, and does not split an answer over several HCI
   commands; the controller refuses what is wrong, and user space gets
   the error. Should the kernel do more here?

4. The controller's Too Late error (0x46) reaches user space as the
   generic Failed. Is a MGMT status of its own wanted?

5. The two events go to all MGMT sockets. Should they go only to the
   socket which added the instance?

Not in this series:

 - periodic advertising data of more than one HCI command (252 octets);
 - Periodic Advertising Sync Transfer over MGMT (the tests send
   LE Periodic Advertising Set Info Transfer with HCI Cmd Sync);
 - connecting to a synchronised device through a subevent
   (LE Extended Create Connection [v2]);
 - the scanner side.

A known gap: if the controller never answers LE Set Periodic
Advertising Subevent Data, its MGMT command stays pending, and the
answer to the next one is taken for it. The PIN code replies have the
same weakness; I have not solved it here.

Patch 2 is needed by the others but stands on its own: the controller
refuses to remove an advertising set while periodic advertising is
enabled on it.

Tested in two ways.

With the BlueZ emulator: the BlueZ series adds the PAwR advertiser to
btdev and 31 mgmt-tester cases for the three commands, among them a
second instance, controllers without the features, Remove Advertising
and Set Powered off with a train running, and subevent data which is
too early, too late or sent in two commands at once. mgmt-tester
passes 560 of 560. Without patch 2 the removal and the power off cases
fail. The other testers pass as before: iso 213, l2cap 144, sco 30,
ioctl 28, mesh 10, smp 8, userchan 4. No KASAN or lockdep reports.

With a real controller, in QEMU: the Nordic SoftDevice Controller on a
simulated nRF52 (BabbleSim), with Zephyr's periodic_sync_rsp sample as
the responder. Plain periodic advertising: the train starts, its data
is set and changed while it runs, the instance is removed. PAwR: the
train starts, the responder is connected and synchronised by PAST,
90 data requests in 8 s are all answered in time and the responses
arrive. An earlier state of the PAwR patches, ported to 6.6, runs the
same on an i.MX93 board.

The Bluetooth code builds with W=1 without warnings. I could not run
sparse, a 32-bit build or an LLVM build here.

The BlueZ side (doc/mgmt-protocol.rst, btmon decoding, btmgmt
commands, emulator and tests) is posted as
"[RFC PATCH BlueZ 0/9] Periodic advertising and PAwR over MGMT".

Roland Schober (5):
  Bluetooth: hci: Add Periodic Advertising with Responses definitions
  Bluetooth: hci_sync: Disable periodic advertising before removing a
    set
  Bluetooth: MGMT: Add Add Periodic Advertising Parameters command
  Bluetooth: MGMT: Add Add Periodic Advertising Data command
  Bluetooth: MGMT: Add PAwR subevent data and response reports

 include/net/bluetooth/hci.h      |  59 +++++
 include/net/bluetooth/hci_core.h |  20 ++
 include/net/bluetooth/hci_sync.h |   2 +
 include/net/bluetooth/mgmt.h     |  89 +++++++
 net/bluetooth/hci_event.c        |  90 ++++++++
 net/bluetooth/hci_sync.c         | 104 ++++++++-
 net/bluetooth/mgmt.c             | 382 +++++++++++++++++++++++++++++++
 7 files changed, 745 insertions(+), 1 deletion(-)

-- 
2.47.3


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFC PATCH 1/5] Bluetooth: hci: Add Periodic Advertising with Responses definitions
  2026-11-27  8:53 [RFC PATCH 0/5] Bluetooth: Periodic advertising and PAwR over MGMT Roland Schober
@ 2026-11-27  8:53 ` Roland Schober
  2026-11-27  8:53 ` [RFC PATCH 2/5] Bluetooth: hci_sync: Disable periodic advertising before removing a set Roland Schober
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Roland Schober @ 2026-11-27  8:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, marcel, Roland Schober

Add the HCI definitions of the advertiser side of Periodic Advertising
with Responses (PAwR), from the Bluetooth Core Specification 5.4:

 - the LE feature bits of the PAwR advertiser and scanner;
 - LE Set Periodic Advertising Parameters [v2], which adds the subevent
   and response slot timing to the periodic advertising parameters;
 - LE Set Periodic Advertising Subevent Data, by which the host hands
   the controller the data of the next subevents;
 - LE Periodic Advertising Subevent Data Request, by which the
   controller asks for that data;
 - LE Periodic Advertising Response Report, which carries the responses
   received in the response slots of a subevent.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Roland Schober <rolandschober1968@gmail.com>
---
 include/net/bluetooth/hci.h      | 59 ++++++++++++++++++++++++++++++++
 include/net/bluetooth/hci_core.h |  6 ++++
 2 files changed, 65 insertions(+)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index ac64780274a5..81ff64dc82ac 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -659,6 +659,8 @@ enum {
 #define HCI_LE_ISO_BROADCASTER		0x40
 #define HCI_LE_ISO_SYNC_RECEIVER	0x80
 #define HCI_LE_LL_EXT_FEATURE		0x80
+#define HCI_LE_PAWR_ADVERTISER		0x08	/* byte 5 */
+#define HCI_LE_PAWR_SCANNER		0x10	/* byte 5 */
 #define HCI_LE_CS			0x40
 #define HCI_LE_CS_HOST			0x80
 #define HCI_LE_SCI			0x01	/* byte 9 - Shorter Connection Intervals */
@@ -2294,6 +2296,37 @@ struct hci_cp_le_set_host_feature {
 	__u8     bit_value;
 } __packed;
 
+struct hci_le_per_adv_subevent_data {
+	__u8    subevent;
+	__u8    response_slot_start;
+	__u8    response_slot_count;
+	__u8    data_len;
+	__u8    data[] __counted_by(data_len);
+} __packed;
+
+/* What fits one command next to handle and num_subevents */
+#define HCI_MAX_PER_ADV_SUBEVENT_DATA_LEN	253
+
+#define HCI_OP_LE_SET_PER_ADV_SUBEVENT_DATA	0x2082
+struct hci_cp_le_set_per_adv_subevent_data {
+	__u8    handle;
+	__u8    num_subevents;
+	__u8    subevents[];
+} __packed;
+
+#define HCI_OP_LE_SET_PER_ADV_PARAMS_V2		0x2086
+struct hci_cp_le_set_per_adv_params_v2 {
+	__u8    handle;
+	__le16  min_interval;
+	__le16  max_interval;
+	__le16  periodic_properties;
+	__u8    num_subevents;
+	__u8    subevent_interval;
+	__u8    response_slot_delay;
+	__u8    response_slot_spacing;
+	__u8    num_response_slots;
+} __packed;
+
 #define HCI_OP_LE_READ_ALL_LOCAL_FEATURES	0x2087
 struct hci_rp_le_read_all_local_features {
 	__u8    status;
@@ -3380,6 +3413,32 @@ struct hci_evt_le_big_info_adv_report {
 	__u8    encryption;
 } __packed;
 
+#define HCI_EV_LE_PER_ADV_SUBEVENT_DATA_REQ	0x27
+struct hci_ev_le_per_adv_subevent_data_req {
+	__u8    handle;
+	__u8    subevent_start;
+	__u8    subevent_data_count;
+} __packed;
+
+struct hci_le_per_adv_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;
+
+#define HCI_EV_LE_PER_ADV_RESPONSE_REPORT	0x28
+struct hci_ev_le_per_adv_response_report {
+	__u8    handle;
+	__u8    subevent;
+	__u8    tx_status;
+	__u8    num_responses;
+	__u8    responses[];
+} __packed;
+
 #define HCI_EVT_LE_ALL_REMOTE_FEATURES_COMPLETE 0x2b
 struct hci_evt_le_read_all_remote_features_complete {
 	__u8    status;
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 4aa0b49ae104..250245186702 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -2140,6 +2140,12 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
 /* Periodic advertising support */
 #define per_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_PERIODIC_ADV))
 
+/* Periodic Advertising with Responses support */
+#define pawr_adv_capable(dev) \
+	((dev)->le_features[5] & HCI_LE_PAWR_ADVERTISER)
+#define pawr_scan_capable(dev) \
+	((dev)->le_features[5] & HCI_LE_PAWR_SCANNER)
+
 /* CIS Master/Slave and BIS support */
 #define iso_capable(dev) (cis_capable(dev) || bis_capable(dev))
 #define iso_enabled(dev) (le_enabled(dev) && iso_capable(dev))
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH 2/5] Bluetooth: hci_sync: Disable periodic advertising before removing a set
  2026-11-27  8:53 [RFC PATCH 0/5] Bluetooth: Periodic advertising and PAwR over MGMT Roland Schober
  2026-11-27  8:53 ` [RFC PATCH 1/5] Bluetooth: hci: Add Periodic Advertising with Responses definitions Roland Schober
@ 2026-11-27  8:53 ` Roland Schober
  2026-11-27  8:53 ` [RFC PATCH 3/5] Bluetooth: MGMT: Add Add Periodic Advertising Parameters command Roland Schober
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Roland Schober @ 2026-11-27  8:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, marcel, Roland Schober

The controller answers LE Remove Advertising Set and LE Clear Advertising
Sets with Command Disallowed while periodic advertising is enabled on
a set. Only a BIG enables periodic advertising so far, and its removal
disables it first on its own.

Disable it in the removal itself, so that an instance which is made
periodic over MGMT can be removed with Remove Advertising.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Roland Schober <rolandschober1968@gmail.com>
---
 net/bluetooth/hci_sync.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index ee426ffeaa03..a1c723aad55e 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -2263,6 +2263,13 @@ int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance,
 	if (err)
 		return err;
 
+	/* The controller refuses to remove an advertising set which has
+	 * periodic advertising enabled.
+	 */
+	err = hci_disable_per_advertising_sync(hdev, instance);
+	if (err)
+		return err;
+
 	if (instance) {
 		hci_dev_lock(hdev);
 
@@ -2392,6 +2399,32 @@ int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance,
 	return hci_start_adv_sync(hdev, instance);
 }
 
+/* The controller refuses to clear the advertising sets while one of them has
+ * periodic advertising enabled.
+ */
+static int hci_disable_per_advertising_all_sync(struct hci_dev *hdev)
+{
+	u8 instances[HCI_MAX_ADV_INSTANCES];
+	struct adv_info *adv;
+	u8 i, n = 0;
+	int err;
+
+	hci_dev_lock(hdev);
+	list_for_each_entry(adv, &hdev->adv_instances, list) {
+		if (adv->periodic_enabled && n < ARRAY_SIZE(instances))
+			instances[n++] = adv->instance;
+	}
+	hci_dev_unlock(hdev);
+
+	for (i = 0; i < n; i++) {
+		err = hci_disable_per_advertising_sync(hdev, instances[i]);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
 static int hci_clear_adv_sets_sync(struct hci_dev *hdev, struct sock *sk)
 {
 	int err;
@@ -2404,6 +2437,10 @@ static int hci_clear_adv_sets_sync(struct hci_dev *hdev, struct sock *sk)
 	if (err)
 		return err;
 
+	err = hci_disable_per_advertising_all_sync(hdev);
+	if (err)
+		return err;
+
 	return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CLEAR_ADV_SETS,
 					0, NULL, 0, HCI_CMD_TIMEOUT, sk);
 }
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH 3/5] Bluetooth: MGMT: Add Add Periodic Advertising Parameters command
  2026-11-27  8:53 [RFC PATCH 0/5] Bluetooth: Periodic advertising and PAwR over MGMT Roland Schober
  2026-11-27  8:53 ` [RFC PATCH 1/5] Bluetooth: hci: Add Periodic Advertising with Responses definitions Roland Schober
  2026-11-27  8:53 ` [RFC PATCH 2/5] Bluetooth: hci_sync: Disable periodic advertising before removing a set Roland Schober
@ 2026-11-27  8:53 ` Roland Schober
  2026-11-27  8:53 ` [RFC PATCH 4/5] Bluetooth: MGMT: Add Add Periodic Advertising Data command Roland Schober
  2026-11-27  8:54 ` [RFC PATCH 5/5] Bluetooth: MGMT: Add PAwR subevent data and response reports Roland Schober
  4 siblings, 0 replies; 6+ messages in thread
From: Roland Schober @ 2026-11-27  8:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, marcel, Roland Schober

Periodic advertising can only be started by an ISO broadcast socket so
far. Add a MGMT command which makes an advertising instance periodic:

  Add Extended Advertising Parameters    creates the instance
  Add Periodic Advertising Parameters    makes it periodic (new)
  Add Extended Advertising Data          enables it

The command takes the periodic advertising interval and the parameters
of Periodic Advertising with Responses (PAwR): number of subevents,
subevent interval, response slot delay and spacing, number of response
slots. With a number of subevents of 0 the instance is plain periodic
advertising; otherwise the controller has to support the PAwR
advertiser feature and LE Set Periodic Advertising Parameters [v2] is
used. The values are those of the HCI command, in its units.

The instance has to use the extended advertising PDUs and must not be
connectable. Its extended advertising parameters are set again when the
command runs, since they may have been sent before the instance became
periodic.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Roland Schober <rolandschober1968@gmail.com>
---
 include/net/bluetooth/hci_core.h |   8 ++
 include/net/bluetooth/hci_sync.h |   1 +
 include/net/bluetooth/mgmt.h     |  26 ++++++
 net/bluetooth/hci_sync.c         |  60 ++++++++++++++
 net/bluetooth/mgmt.c             | 133 +++++++++++++++++++++++++++++++
 5 files changed, 228 insertions(+)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 250245186702..117408645b9b 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -260,6 +260,14 @@ struct adv_info {
 	bool	scan_rsp_changed;
 	__u16	per_adv_data_len;
 	__u8	per_adv_data[HCI_MAX_PER_AD_LENGTH];
+	/* Periodic Advertising with Responses, if num_subevents is not 0 */
+	__u16	per_adv_min_interval;
+	__u16	per_adv_max_interval;
+	__u8	num_subevents;
+	__u8	subevent_interval;
+	__u8	response_slot_delay;
+	__u8	response_slot_spacing;
+	__u8	num_response_slots;
 	__s8	tx_power;
 	__u32   min_interval;
 	__u32   max_interval;
diff --git a/include/net/bluetooth/hci_sync.h b/include/net/bluetooth/hci_sync.h
index eab827dfa829..03d7e267af7c 100644
--- a/include/net/bluetooth/hci_sync.h
+++ b/include/net/bluetooth/hci_sync.h
@@ -118,6 +118,7 @@ int hci_start_per_adv_sync(struct hci_dev *hdev, u8 instance, u8 sid,
 			   u16 max_interval, u16 sync_interval);
 
 int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance);
+int hci_setup_per_adv_instance_sync(struct hci_dev *hdev, u8 instance);
 
 int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk,
 				u8 instance, bool force);
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 17bdd6345d19..57b9d8d8b57d 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -912,6 +912,32 @@ struct mgmt_cp_load_conn_subrate {
 } __packed;
 #define MGMT_LOAD_CONN_SUBRATE_SIZE	2
 
+/* Turn an instance added with Add Extended Advertising Parameters into
+ * periodic advertising; with num_subevents not 0, into Periodic Advertising
+ * with Responses.  The values are those of the HCI command, in its units:
+ *
+ *   min_interval, max_interval	1.25 ms (0x0006 to 0xffff)
+ *   subevent_interval		1.25 ms
+ *   response_slot_delay	1.25 ms
+ *   response_slot_spacing	0.125 ms
+ *   num_subevents, num_response_slots	counts
+ */
+#define MGMT_OP_ADD_PERIODIC_ADV_PARAMS	0x005D
+struct mgmt_cp_add_periodic_adv_params {
+	__u8	instance;
+	__le16	min_interval;
+	__le16	max_interval;
+	__u8	num_subevents;
+	__u8	subevent_interval;
+	__u8	response_slot_delay;
+	__u8	response_slot_spacing;
+	__u8	num_response_slots;
+} __packed;
+#define MGMT_ADD_PERIODIC_ADV_PARAMS_SIZE	10
+struct mgmt_rp_add_periodic_adv_params {
+	__u8	instance;
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16	opcode;
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index a1c723aad55e..3d8327180c6e 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -1968,6 +1968,66 @@ static int hci_enable_per_advertising_sync(struct hci_dev *hdev, u8 instance)
 	return 0;
 }
 
+/* Program periodic advertising on an instance and enable it. The extended
+ * advertising parameters are set again first: they may have been chosen
+ * before the instance became periodic, and a periodic instance can neither be
+ * connectable nor use a non-resolvable private address. An instance with
+ * subevents is Periodic Advertising with Responses and takes the [v2]
+ * parameters. The train starts once extended advertising is enabled as well.
+ */
+int hci_setup_per_adv_instance_sync(struct hci_dev *hdev, u8 instance)
+{
+	struct hci_cp_le_set_per_adv_params_v2 cp;
+	struct adv_info *adv;
+	u16 min_interval, max_interval;
+	int err;
+
+	err = hci_disable_per_advertising_sync(hdev, instance);
+	if (err)
+		return err;
+
+	err = hci_setup_ext_adv_instance_sync(hdev, instance);
+	if (err)
+		return err;
+
+	memset(&cp, 0, sizeof(cp));
+
+	hci_dev_lock(hdev);
+
+	adv = hci_find_adv_instance(hdev, instance);
+	if (!adv || !adv->periodic) {
+		hci_dev_unlock(hdev);
+		return -EINVAL;
+	}
+
+	min_interval = adv->per_adv_min_interval;
+	max_interval = adv->per_adv_max_interval;
+
+	cp.handle = adv->handle;
+	cp.min_interval = cpu_to_le16(min_interval);
+	cp.max_interval = cpu_to_le16(max_interval);
+	cp.periodic_properties = 0x0000;
+	cp.num_subevents = adv->num_subevents;
+	cp.subevent_interval = adv->subevent_interval;
+	cp.response_slot_delay = adv->response_slot_delay;
+	cp.response_slot_spacing = adv->response_slot_spacing;
+	cp.num_response_slots = adv->num_response_slots;
+
+	hci_dev_unlock(hdev);
+
+	if (cp.num_subevents)
+		err = __hci_cmd_sync_status(hdev,
+					    HCI_OP_LE_SET_PER_ADV_PARAMS_V2,
+					    sizeof(cp), &cp, HCI_CMD_TIMEOUT);
+	else
+		err = hci_set_per_adv_params_sync(hdev, instance, min_interval,
+						  max_interval);
+	if (err)
+		return err;
+
+	return hci_enable_per_advertising_sync(hdev, instance);
+}
+
 /* Checks if periodic advertising data contains a Basic Announcement and if it
  * does generates a Broadcast ID and add Broadcast Announcement.
  */
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index d21538634bc3..2870278d51b0 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_ADD_PERIODIC_ADV_PARAMS,
 };
 
 static const u16 mgmt_events[] = {
@@ -9797,6 +9798,137 @@ static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data,
 	return err;
 }
 
+static void add_periodic_adv_params_complete(struct hci_dev *hdev, void *data,
+					     int err)
+{
+	struct mgmt_pending_cmd *cmd = data;
+	struct mgmt_cp_add_periodic_adv_params *cp = cmd->param;
+	struct mgmt_rp_add_periodic_adv_params rp;
+	struct adv_info *adv;
+
+	bt_dev_dbg(hdev, "err %d", err);
+
+	if (err) {
+		/* The instance stays as it was added, without periodic
+		 * advertising.
+		 */
+		hci_dev_lock(hdev);
+		adv = hci_find_adv_instance(hdev, cp->instance);
+		if (adv) {
+			adv->periodic = false;
+			adv->num_subevents = 0;
+		}
+		hci_dev_unlock(hdev);
+
+		mgmt_cmd_status(cmd->sk, hdev->id, cmd->opcode,
+				mgmt_status(err));
+	} else {
+		rp.instance = cp->instance;
+		mgmt_cmd_complete(cmd->sk, hdev->id, cmd->opcode,
+				  MGMT_STATUS_SUCCESS, &rp, sizeof(rp));
+	}
+
+	mgmt_pending_free(cmd);
+}
+
+static int add_periodic_adv_params_sync(struct hci_dev *hdev, void *data)
+{
+	struct mgmt_pending_cmd *cmd = data;
+	struct mgmt_cp_add_periodic_adv_params *cp = cmd->param;
+
+	return hci_setup_per_adv_instance_sync(hdev, cp->instance);
+}
+
+static int add_periodic_adv_params(struct sock *sk, struct hci_dev *hdev,
+				   void *data, u16 data_len)
+{
+	struct mgmt_cp_add_periodic_adv_params *cp = data;
+	struct mgmt_pending_cmd *cmd;
+	struct adv_info *adv;
+	u16 min_interval, max_interval;
+	u8 status;
+	int err;
+
+	bt_dev_dbg(hdev, "sock %p", sk);
+
+	status = mgmt_le_support(hdev);
+	if (status)
+		return mgmt_cmd_status(sk, hdev->id,
+				       MGMT_OP_ADD_PERIODIC_ADV_PARAMS, status);
+
+	if (!ext_adv_capable(hdev) || !per_adv_capable(hdev) ||
+	    (cp->num_subevents && !pawr_adv_capable(hdev)))
+		return mgmt_cmd_status(sk, hdev->id,
+				       MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+				       MGMT_STATUS_NOT_SUPPORTED);
+
+	min_interval = __le16_to_cpu(cp->min_interval);
+	max_interval = __le16_to_cpu(cp->max_interval);
+
+	if (min_interval < 0x0006 || min_interval > max_interval ||
+	    cp->num_subevents > 0x80)
+		return mgmt_cmd_status(sk, hdev->id,
+				       MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+				       MGMT_STATUS_INVALID_PARAMS);
+
+	hci_dev_lock(hdev);
+
+	if (!hdev_is_powered(hdev)) {
+		err = mgmt_cmd_status(sk, hdev->id,
+				      MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+				      MGMT_STATUS_REJECTED);
+		goto unlock;
+	}
+
+	/* Periodic advertising needs an advertising set which uses the
+	 * extended PDUs and is not connectable.
+	 */
+	adv = hci_find_adv_instance(hdev, cp->instance);
+	if (!adv || !(adv->flags & MGMT_ADV_FLAG_SEC_MASK) ||
+	    (adv->flags & MGMT_ADV_FLAG_CONNECTABLE)) {
+		err = mgmt_cmd_status(sk, hdev->id,
+				      MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+				      MGMT_STATUS_INVALID_PARAMS);
+		goto unlock;
+	}
+
+	if (adv_overridden_by_global(hdev, adv)) {
+		err = mgmt_cmd_status(sk, hdev->id,
+				      MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+				      MGMT_STATUS_BUSY);
+		goto unlock;
+	}
+
+	cmd = mgmt_pending_new(sk, MGMT_OP_ADD_PERIODIC_ADV_PARAMS, hdev, data,
+			       data_len);
+	if (!cmd) {
+		err = -ENOMEM;
+		goto unlock;
+	}
+
+	adv->periodic = true;
+	adv->per_adv_min_interval = min_interval;
+	adv->per_adv_max_interval = max_interval;
+	adv->num_subevents = cp->num_subevents;
+	adv->subevent_interval = cp->subevent_interval;
+	adv->response_slot_delay = cp->response_slot_delay;
+	adv->response_slot_spacing = cp->response_slot_spacing;
+	adv->num_response_slots = cp->num_response_slots;
+
+	err = hci_cmd_sync_queue(hdev, add_periodic_adv_params_sync, cmd,
+				 add_periodic_adv_params_complete);
+	if (err < 0) {
+		adv->periodic = false;
+		adv->num_subevents = 0;
+		mgmt_pending_free(cmd);
+	}
+
+unlock:
+	hci_dev_unlock(hdev);
+
+	return err;
+}
+
 static void remove_advertising_complete(struct hci_dev *hdev, void *data,
 					int err)
 {
@@ -10058,6 +10190,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 },
+	{ add_periodic_adv_params, MGMT_ADD_PERIODIC_ADV_PARAMS_SIZE },
 };
 
 void mgmt_index_added(struct hci_dev *hdev)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH 4/5] Bluetooth: MGMT: Add Add Periodic Advertising Data command
  2026-11-27  8:53 [RFC PATCH 0/5] Bluetooth: Periodic advertising and PAwR over MGMT Roland Schober
                   ` (2 preceding siblings ...)
  2026-11-27  8:53 ` [RFC PATCH 3/5] Bluetooth: MGMT: Add Add Periodic Advertising Parameters command Roland Schober
@ 2026-11-27  8:53 ` Roland Schober
  2026-11-27  8:54 ` [RFC PATCH 5/5] Bluetooth: MGMT: Add PAwR subevent data and response reports Roland Schober
  4 siblings, 0 replies; 6+ messages in thread
From: Roland Schober @ 2026-11-27  8:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, marcel, Roland Schober

Add a MGMT command which sets the data of the periodic advertising
train of an instance made periodic with Add Periodic Advertising
Parameters. It can be sent again to change the data while the train
runs.

The data is limited to what one LE Set Periodic Advertising Data
command takes, as the data of a BIG is. An instance with subevents is
refused: the controller does not allow the command for it.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Roland Schober <rolandschober1968@gmail.com>
---
 include/net/bluetooth/hci_sync.h |  1 +
 include/net/bluetooth/mgmt.h     | 14 +++++
 net/bluetooth/hci_sync.c         |  2 +-
 net/bluetooth/mgmt.c             | 87 ++++++++++++++++++++++++++++++++
 4 files changed, 103 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci_sync.h b/include/net/bluetooth/hci_sync.h
index 03d7e267af7c..e6d3d3de482e 100644
--- a/include/net/bluetooth/hci_sync.h
+++ b/include/net/bluetooth/hci_sync.h
@@ -119,6 +119,7 @@ int hci_start_per_adv_sync(struct hci_dev *hdev, u8 instance, u8 sid,
 
 int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance);
 int hci_setup_per_adv_instance_sync(struct hci_dev *hdev, u8 instance);
+int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance);
 
 int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk,
 				u8 instance, bool force);
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 57b9d8d8b57d..a46e87a9152c 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -938,6 +938,20 @@ struct mgmt_rp_add_periodic_adv_params {
 	__u8	instance;
 } __packed;
 
+/* The data of the periodic advertising train of an instance made periodic
+ * with Add Periodic Advertising Parameters.
+ */
+#define MGMT_OP_ADD_PERIODIC_ADV_DATA	0x005E
+struct mgmt_cp_add_periodic_adv_data {
+	__u8	instance;
+	__u8	data_len;
+	__u8	data[] __counted_by(data_len);
+} __packed;
+#define MGMT_ADD_PERIODIC_ADV_DATA_SIZE	2
+struct mgmt_rp_add_periodic_adv_data {
+	__u8	instance;
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16	opcode;
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 3d8327180c6e..05151cf6f413 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -1896,7 +1896,7 @@ static int hci_set_per_adv_params_sync(struct hci_dev *hdev, u8 instance,
 				     sizeof(cp), &cp, HCI_CMD_TIMEOUT);
 }
 
-static int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance)
+int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance)
 	__context_unsafe(/* conditional locking */)
 {
 	DEFINE_FLEX(struct hci_cp_le_set_per_adv_data, pdu, data, length,
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 2870278d51b0..0f8a58ad1e3c 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -131,6 +131,7 @@ static const u16 mgmt_commands[] = {
 	MGMT_OP_MESH_SEND_CANCEL,
 	MGMT_OP_HCI_CMD_SYNC,
 	MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+	MGMT_OP_ADD_PERIODIC_ADV_DATA,
 };
 
 static const u16 mgmt_events[] = {
@@ -9929,6 +9930,90 @@ static int add_periodic_adv_params(struct sock *sk, struct hci_dev *hdev,
 	return err;
 }
 
+static void add_periodic_adv_data_complete(struct hci_dev *hdev, void *data,
+					   int err)
+{
+	struct mgmt_pending_cmd *cmd = data;
+	struct mgmt_cp_add_periodic_adv_data *cp = cmd->param;
+	struct mgmt_rp_add_periodic_adv_data rp;
+
+	bt_dev_dbg(hdev, "err %d", err);
+
+	if (err) {
+		mgmt_cmd_status(cmd->sk, hdev->id, cmd->opcode,
+				mgmt_status(err));
+	} else {
+		rp.instance = cp->instance;
+		mgmt_cmd_complete(cmd->sk, hdev->id, cmd->opcode,
+				  MGMT_STATUS_SUCCESS, &rp, sizeof(rp));
+	}
+
+	mgmt_pending_free(cmd);
+}
+
+static int add_periodic_adv_data_sync(struct hci_dev *hdev, void *data)
+{
+	struct mgmt_pending_cmd *cmd = data;
+	struct mgmt_cp_add_periodic_adv_data *cp = cmd->param;
+
+	return hci_set_per_adv_data_sync(hdev, cp->instance);
+}
+
+static int add_periodic_adv_data(struct sock *sk, struct hci_dev *hdev,
+				 void *data, u16 data_len)
+{
+	struct mgmt_cp_add_periodic_adv_data *cp = data;
+	struct mgmt_pending_cmd *cmd;
+	struct adv_info *adv;
+	int err;
+
+	bt_dev_dbg(hdev, "sock %p", sk);
+
+	if (data_len != struct_size(cp, data, cp->data_len) ||
+	    cp->data_len > HCI_MAX_PER_AD_LENGTH)
+		return mgmt_cmd_status(sk, hdev->id,
+				       MGMT_OP_ADD_PERIODIC_ADV_DATA,
+				       MGMT_STATUS_INVALID_PARAMS);
+
+	hci_dev_lock(hdev);
+
+	if (!hdev_is_powered(hdev)) {
+		err = mgmt_cmd_status(sk, hdev->id,
+				      MGMT_OP_ADD_PERIODIC_ADV_DATA,
+				      MGMT_STATUS_REJECTED);
+		goto unlock;
+	}
+
+	/* The data of an instance with subevents is that of its subevents */
+	adv = hci_find_adv_instance(hdev, cp->instance);
+	if (!adv || !adv->periodic || adv->num_subevents) {
+		err = mgmt_cmd_status(sk, hdev->id,
+				      MGMT_OP_ADD_PERIODIC_ADV_DATA,
+				      MGMT_STATUS_INVALID_PARAMS);
+		goto unlock;
+	}
+
+	cmd = mgmt_pending_new(sk, MGMT_OP_ADD_PERIODIC_ADV_DATA, hdev, data,
+			       data_len);
+	if (!cmd) {
+		err = -ENOMEM;
+		goto unlock;
+	}
+
+	adv->per_adv_data_len = cp->data_len;
+	memcpy(adv->per_adv_data, cp->data, cp->data_len);
+
+	err = hci_cmd_sync_queue(hdev, add_periodic_adv_data_sync, cmd,
+				 add_periodic_adv_data_complete);
+	if (err < 0)
+		mgmt_pending_free(cmd);
+
+unlock:
+	hci_dev_unlock(hdev);
+
+	return err;
+}
+
 static void remove_advertising_complete(struct hci_dev *hdev, void *data,
 					int err)
 {
@@ -10191,6 +10276,8 @@ static const struct hci_mgmt_handler mgmt_handlers[] = {
 	{ load_conn_subrate,       MGMT_LOAD_CONN_SUBRATE_SIZE,
 						HCI_MGMT_VAR_LEN },
 	{ add_periodic_adv_params, MGMT_ADD_PERIODIC_ADV_PARAMS_SIZE },
+	{ add_periodic_adv_data,   MGMT_ADD_PERIODIC_ADV_DATA_SIZE,
+						HCI_MGMT_VAR_LEN },
 };
 
 void mgmt_index_added(struct hci_dev *hdev)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH 5/5] Bluetooth: MGMT: Add PAwR subevent data and response reports
  2026-11-27  8:53 [RFC PATCH 0/5] Bluetooth: Periodic advertising and PAwR over MGMT Roland Schober
                   ` (3 preceding siblings ...)
  2026-11-27  8:53 ` [RFC PATCH 4/5] Bluetooth: MGMT: Add Add Periodic Advertising Data command Roland Schober
@ 2026-11-27  8:54 ` Roland Schober
  4 siblings, 0 replies; 6+ messages in thread
From: Roland Schober @ 2026-11-27  8:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, marcel, Roland Schober

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 <rolandschober1968@gmail.com>
---
 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 a9b6a6ccaa03..b88dad2eadf3 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -4598,6 +4598,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, \
@@ -4774,6 +4788,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),
@@ -8128,6 +8146,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)
 {
@@ -8437,6 +8518,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 0f8a58ad1e3c..037cb8513a11 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-27  8:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27  8:53 [RFC PATCH 0/5] Bluetooth: Periodic advertising and PAwR over MGMT Roland Schober
2026-11-27  8:53 ` [RFC PATCH 1/5] Bluetooth: hci: Add Periodic Advertising with Responses definitions Roland Schober
2026-11-27  8:53 ` [RFC PATCH 2/5] Bluetooth: hci_sync: Disable periodic advertising before removing a set Roland Schober
2026-11-27  8:53 ` [RFC PATCH 3/5] Bluetooth: MGMT: Add Add Periodic Advertising Parameters command Roland Schober
2026-11-27  8:53 ` [RFC PATCH 4/5] Bluetooth: MGMT: Add Add Periodic Advertising Data command Roland Schober
2026-11-27  8:54 ` [RFC PATCH 5/5] Bluetooth: MGMT: Add PAwR subevent data and response reports Roland Schober

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox