Linux bluetooth development
 help / color / mirror / Atom feed
* [RFC PATCH BlueZ v2 0/9] Periodic advertising and PAwR over MGMT
@ 2026-12-02 12:52 Roland Schober
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 1/9] doc/mgmt: Add PA and PAwR commands and events Roland Schober
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Roland Schober @ 2026-12-02 12:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Roland Schober

This is the user space side of the kernel RFC
"[RFC PATCH 0/5] Bluetooth: Periodic advertising and PAwR over MGMT":
a MGMT interface for periodic advertising and for the advertiser side
of Periodic Advertising with Responses (PAwR), with emulator support
and tests. The kernel series is unchanged, the interface is the one
of v1.

Patch 1 documents the three commands and two events in
doc/mgmt-protocol.rst; it is the place to comment on the interface.
Patch 2 adds the definitions, patch 3 the btmon decoding.

Patch 4 fixes the length which btmgmt takes of a byte array with empty
entries, which the new commands use. Patch 5 adds three btmgmt
commands: pa-params sends Add Periodic Advertising Parameters, pa-data
sends Add Periodic Advertising Data, pawr-serve answers the subevent
data requests and prints the response reports.

Plain periodic advertising:

  btmgmt add-ext-adv-params -P 1M 1
  btmgmt pa-params 1 0x50 0x50
  btmgmt pa-data 1 0x05 0xff 0x59 0x00 0x01 0x02
  btmgmt add-ext-adv-data 1

A PAwR train with 5 subevents of 5 response slots:

  btmgmt add-ext-adv-params -P 1M 1
  btmgmt pa-params 1 0xff 0xff 5 0x30 8 0x50 5
  btmgmt pawr-serve 1 5 5 &
  btmgmt add-ext-adv-data 1

Patches 6 to 8 are the emulator:

 - Patch 6 adds the PAwR HCI definitions to bt.h. They are the ones of
   my btmon series "monitor: Decode Periodic Advertising with
   Responses", which is not applied yet; the patch is dropped here
   when that series is in.
 - Patch 7 makes the emulator refuse to remove an advertising set
   while periodic advertising is enabled on it, as a controller does.
   The kernel needs "Bluetooth: hci_sync: Disable PA before removing
   an advertising set" for this, which is part of the kernel RFC and
   which I also sent on its own. Without it the broadcast cases of
   test/functional/test_bap.py fail, as the CI run of v1 showed.
 - Patch 8 adds the PAwR advertiser to controllers of version 6.0 and
   later: the parameters [v2], the subevent data requests once per
   periodic advertising interval, and the subevent data command, which
   refuses data that was not asked for. Nothing is transmitted: the
   responder side and the response reports are not emulated yet.

Patch 9 adds 32 mgmt-tester cases. They need the kernel series; on a
kernel without it they fail.

Also tested with the kernel RFC in QEMU against the Nordic SoftDevice
Controller on a simulated nRF52 (BabbleSim), with Zephyr's
periodic_sync_rsp sample as the responder. That run covers what the
emulator does not: a synchronised responder and its response reports.

The D-Bus API is not part of this RFC; it follows when the MGMT
interface is agreed. For PAwR I expect bluetoothd to keep the data of
each subevent and to answer the data requests itself, since a D-Bus
round trip per request does not fit the controller's lead time.

v2:
 - btmgmt pawr-serve: do not write beyond the command buffer, send
   data which does not fit one command in several, check the arguments
   before the running configuration is changed, and replace an earlier
   pawr-serve instead of answering twice. Copilot found these four.
 - btmgmt: refuse numbers out of range, take the data from all
   remaining arguments, size the buffer which prints a response for
   the largest data length. Add patch 4 and the commands to
   doc/bluetoothctl-mgmt.rst.
 - Emulator: a refused LE Set Periodic Advertising Enable leaves the
   train as it is (Copilot). Check the response slot spacing against
   the subevent interval, refuse a command which names a subevent
   twice, and forget the subevents of a set which is removed.
 - Emulator: answer Command Disallowed for subevent data before the
   first request, for a second command for one subevent and for a
   subevent the train does not have, as the Core Specification lists
   it. v1 answered Too Early and Too Late, which are for data that
   misses its subevent in time; the patch with their definitions is
   dropped.
 - mgmt-tester: send the two commands of the "two commands" test
   without waiting for the first reply (Copilot), use a periodic
   advertising interval of 400 ms, which leaves time to answer, and
   add a case for a subevent the train does not have.
 - doc/mgmt-protocol.rst: a command takes the data of up to 15
   subevents.
 - The trace in the commit message of patch 3 is a complete excerpt.
 - Shorter subjects for patches 1, 3, 7 and 8.
 - Rebased.

Roland Schober (9):
  doc/mgmt: Add PA and PAwR commands and events
  lib/mgmt: Add periodic advertising and PAwR definitions
  monitor: Decode PA and PAwR MGMT commands and events
  client/mgmt: Fix length of byte arrays with empty entries
  client/mgmt: Add pa-params, pa-data and pawr-serve commands
  monitor: Add PAwR HCI definitions
  emulator/btdev: Keep advertising sets with PA enabled
  emulator/btdev: Add PAwR advertiser
  mgmt-tester: Add periodic advertising and PAwR tests

 client/mgmt.c             |  373 ++++++++++++-
 doc/bluetoothctl-mgmt.rst |   51 ++
 doc/mgmt-protocol.rst     |  208 ++++++++
 emulator/btdev.c          |  306 ++++++++++-
 lib/bluetooth/mgmt.h      |   74 +++
 monitor/bt.h              |  174 ++++++
 monitor/packet.c          |  204 +++++++
 tools/mgmt-tester.c       | 1068 +++++++++++++++++++++++++++++++++++++
 8 files changed, 2453 insertions(+), 5 deletions(-)


base-commit: eecfd959cf5ae9a24ee007975439747779804be1
-- 
2.47.3


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

* [RFC PATCH BlueZ v2 1/9] doc/mgmt: Add PA and PAwR commands and events
  2026-12-02 12:52 [RFC PATCH BlueZ v2 0/9] Periodic advertising and PAwR over MGMT Roland Schober
@ 2026-12-02 12:52 ` Roland Schober
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 2/9] lib/mgmt: Add periodic advertising and PAwR definitions Roland Schober
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Roland Schober @ 2026-12-02 12:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Roland Schober

Add Periodic Advertising Parameters makes an advertising instance
periodic and, with subevents, Periodic Advertising with Responses.
Add Periodic Advertising Data sets the data of a periodic advertising
train. Set Periodic Advertising Subevent Data and the events Periodic
Advertising Subevent Data Request and Periodic Advertising Response
Report carry the data of the subevents and the responses to them.

Assisted-by: Claude:claude-fable-5-2
---
 doc/mgmt-protocol.rst | 208 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 208 insertions(+)

diff --git a/doc/mgmt-protocol.rst b/doc/mgmt-protocol.rst
index c4e1421e3..1bab75858 100644
--- a/doc/mgmt-protocol.rst
+++ b/doc/mgmt-protocol.rst
@@ -4278,6 +4278,153 @@ Possible errors:
 :Invalid Index:
 :Not Supported:
 
+Add Periodic Advertising Parameters
+```````````````````````````````````
+
+:Command Code:		0x005D
+:Controller Index:	<controller id>
+:Command Parameters:	Instance (1 Octet)
+:...:			Min_Interval (2 Octets)
+:...:			Max_Interval (2 Octets)
+:...:			Num_Subevents (1 Octet)
+:...:			Subevent_Interval (1 Octet)
+:...:			Response_Slot_Delay (1 Octet)
+:...:			Response_Slot_Spacing (1 Octet)
+:...:			Num_Response_Slots (1 Octet)
+:Return Parameters:	Instance (1 Octet)
+
+This command is used to make an advertising instance a periodic advertising
+instance. The instance has to exist: the command is sent between Add Extended
+Advertising Parameters, which creates the instance, and Add Extended
+Advertising Data, which enables it:
+
+.. csv-table::
+	:header: "Step", "Command"
+	:widths: auto
+
+	1, Add Extended Advertising Parameters
+	2, Add Periodic Advertising Parameters
+	3, Add Periodic Advertising Data (optional)
+	4, Add Extended Advertising Data
+
+The instance must use one of the secondary channel flags (Secondary Channel
+with LE 1M, LE 2M or LE Coded) and must not be connectable.
+
+The Min_Interval and Max_Interval parameters specify the range of the periodic
+advertising interval in units of 1.25 ms (range: 0x0006 to 0xFFFF).
+
+A Num_Subevents of 0 makes the instance plain periodic advertising, and the
+remaining parameters are ignored. Any other value (range: 0x01 to 0x80) makes
+it Periodic Advertising with Responses, which requires the controller to
+support the Periodic Advertising with Responses - Advertiser feature. The
+remaining parameters are then those of the HCI command LE Set Periodic
+Advertising Parameters [v2]:
+
+.. csv-table::
+	:header: "Parameter", "Unit", "Description"
+	:widths: auto
+
+	Subevent_Interval, 1.25 ms, Time between the subevents of one periodic advertising event
+	Response_Slot_Delay, 1.25 ms, Time from the start of a subevent to its first response slot
+	Response_Slot_Spacing, 0.125 ms, Time between the starts of two response slots
+	Num_Response_Slots, , Number of response slots of a subevent
+
+The controller checks these values against each other and against the
+interval. The data of the subevents is requested with the Periodic Advertising
+Subevent Data Request event.
+
+Remove Advertising stops the periodic advertising and removes the instance.
+
+This command can only be used when the controller is powered.
+
+This command generates a Command Complete event on success or a Command Status
+event on failure.
+
+Possible errors:
+
+:Failed:
+:Busy:
+:Rejected:
+:Not Supported:
+:Invalid Parameters:
+:Invalid Index:
+
+Add Periodic Advertising Data
+`````````````````````````````
+
+:Command Code:		0x005E
+:Controller Index:	<controller id>
+:Command Parameters:	Instance (1 Octet)
+:...:			Data_Length (1 Octet)
+:...:			Data (0-252 Octets)
+:Return Parameters:	Instance (1 Octet)
+
+This command is used to set the data of the periodic advertising train of an
+instance which was made periodic with Add Periodic Advertising Parameters. It
+may be sent again to change the data while the train is running.
+
+The Data parameter holds advertising data structures, each with its length
+and type. The kernel does not add anything to it.
+
+An instance with Periodic Advertising with Responses has no such data: the
+data of its subevents is set with Set Periodic Advertising Subevent Data.
+
+This command can only be used when the controller is powered.
+
+This command generates a Command Complete event on success or a Command Status
+event on failure.
+
+Possible errors:
+
+:Failed:
+:Rejected:
+:Invalid Parameters:
+:Invalid Index:
+
+Set Periodic Advertising Subevent Data
+``````````````````````````````````````
+
+:Command Code:		0x005F
+:Controller Index:	<controller id>
+:Command Parameters:	Instance (1 Octet)
+:...:			Num_Subevents (1 Octet)
+:...:			Subevent[] (1 Octet)
+:...:			Response_Slot_Start[] (1 Octet)
+:...:			Response_Slot_Count[] (1 Octet)
+:...:			Data_Length[] (1 Octet)
+:...:			Data[] (variable)
+:...:			...[]
+:Return Parameters:	Instance (1 Octet)
+
+This command is used to set the data of subevents of an instance with
+Periodic Advertising with Responses. It is the answer to the Periodic
+Advertising Subevent Data Request event and may hold the data of any number of
+the requested subevents.
+
+The Response_Slot_Start and Response_Slot_Count parameters specify the
+response slots of the subevent the controller listens to. A count of 0 means
+that no response is expected.
+
+All entries of one command are sent to the controller in a single HCI command,
+which takes the data of up to 15 subevents: the entries, each with its four
+octets of header, are limited to 253 octets in total.
+
+The controller accepts the data of a subevent only for a limited time before
+the subevent. Data which arrives too late, or for a subevent which was not
+requested, fails the command, and nothing is transmitted in that subevent.
+
+This command can only be used when the controller is powered.
+
+This command generates a Command Complete event on success or a Command Status
+event on failure.
+
+Possible errors:
+
+:Failed:
+:Rejected:
+:Invalid Parameters:
+:Invalid Index:
+
 Events
 ------
 
@@ -5599,3 +5746,64 @@ Possible values for the Encryption type:
 	0x02, AES-CCM encryption
 
 This event will be sent to all management sockets.
+
+Periodic Advertising Subevent Data Request
+``````````````````````````````````````````
+
+:Event Code:		0x0035
+:Controller Index:	<controller id>
+:Event Parameters:	Instance (1 Octet)
+:...:			Subevent_Start (1 Octet)
+:...:			Subevent_Data_Count (1 Octet)
+
+This event indicates that the controller is ready to accept the data of
+Subevent_Data_Count subevents of an instance with Periodic Advertising with
+Responses, starting with the subevent Subevent_Start and wrapping to subevent
+0 after the last one. The data is set with the Set
+Periodic Advertising Subevent Data command.
+
+This event will be sent to all management sockets.
+
+Periodic Advertising Response Report
+````````````````````````````````````
+
+:Event Code:		0x0036
+:Controller Index:	<controller id>
+:Event Parameters:	Instance (1 Octet)
+:...:			Subevent (1 Octet)
+:...:			TX_Status (1 Octet)
+:...:			Num_Responses (1 Octet)
+:...:			TX_Power[] (1 Octet)
+:...:			RSSI[] (1 Octet)
+:...:			CTE_Type[] (1 Octet)
+:...:			Response_Slot[] (1 Octet)
+:...:			Data_Status[] (1 Octet)
+:...:			Data_Length[] (1 Octet)
+:...:			Data[] (variable)
+:...:			...[]
+
+This event reports the responses received in the response slots of a subevent
+of an instance with Periodic Advertising with Responses.
+
+Possible values for the TX_Status parameter:
+
+.. csv-table::
+	:header: "Value", "Description"
+	:widths: auto
+
+	0x00, The subevent was transmitted
+	0x01, The subevent was not transmitted
+
+The parameters of a response are those of the HCI event LE Periodic
+Advertising Response Report. TX_Power and RSSI are in dBm, with 0x7F for a
+value which is not available. Possible values for the Data_Status parameter:
+
+.. csv-table::
+	:header: "Value", "Description"
+	:widths: auto
+
+	0x00, Data complete
+	0x01, "Data incomplete, more data to come"
+	0xFF, Failed to receive the response
+
+This event will be sent to all management sockets.
-- 
2.47.3


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

* [RFC PATCH BlueZ v2 2/9] lib/mgmt: Add periodic advertising and PAwR definitions
  2026-12-02 12:52 [RFC PATCH BlueZ v2 0/9] Periodic advertising and PAwR over MGMT Roland Schober
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 1/9] doc/mgmt: Add PA and PAwR commands and events Roland Schober
@ 2026-12-02 12:52 ` Roland Schober
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 3/9] monitor: Decode PA and PAwR MGMT commands and events Roland Schober
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Roland Schober @ 2026-12-02 12:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Roland Schober

Add the MGMT commands and events for periodic advertising and Periodic
Advertising with Responses (PAwR):

 - Add Periodic Advertising Parameters (0x005d)
 - Add Periodic Advertising Data (0x005e)
 - Set Periodic Advertising Subevent Data (0x005f)
 - Periodic Advertising Subevent Data Request event (0x0035)
 - Periodic Advertising Response Report event (0x0036)

Assisted-by: Claude:claude-fable-5-2
---
 lib/bluetooth/mgmt.h | 74 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/lib/bluetooth/mgmt.h b/lib/bluetooth/mgmt.h
index af71be828..450d20afb 100644
--- a/lib/bluetooth/mgmt.h
+++ b/lib/bluetooth/mgmt.h
@@ -838,6 +838,49 @@ struct mgmt_cp_load_conn_subrate {
 	struct mgmt_conn_subrate params[];
 } __packed;
 
+#define MGMT_OP_ADD_PERIODIC_ADV_PARAMS	0x005D
+struct mgmt_cp_add_periodic_adv_params {
+	uint8_t  instance;
+	uint16_t min_interval;
+	uint16_t max_interval;
+	uint8_t  num_subevents;
+	uint8_t  subevent_interval;
+	uint8_t  response_slot_delay;
+	uint8_t  response_slot_spacing;
+	uint8_t  num_response_slots;
+} __packed;
+struct mgmt_rp_add_periodic_adv_params {
+	uint8_t  instance;
+} __packed;
+
+#define MGMT_OP_ADD_PERIODIC_ADV_DATA	0x005E
+struct mgmt_cp_add_periodic_adv_data {
+	uint8_t  instance;
+	uint8_t  data_len;
+	uint8_t  data[];
+} __packed;
+struct mgmt_rp_add_periodic_adv_data {
+	uint8_t  instance;
+} __packed;
+
+struct mgmt_pa_subevent_data {
+	uint8_t  subevent;
+	uint8_t  response_slot_start;
+	uint8_t  response_slot_count;
+	uint8_t  data_len;
+	uint8_t  data[];
+} __packed;
+
+#define MGMT_OP_SET_PA_SUBEVENT_DATA	0x005F
+struct mgmt_cp_set_pa_subevent_data {
+	uint8_t  instance;
+	uint8_t  num_subevents;
+	uint8_t  subevents[];
+} __packed;
+struct mgmt_rp_set_pa_subevent_data {
+	uint8_t  instance;
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	uint16_t opcode;
@@ -1156,6 +1199,32 @@ struct mgmt_ev_security_level_changed {
 	uint8_t	tlv_data[];
 } __packed;
 
+#define MGMT_EV_PA_SUBEVENT_DATA_REQUEST	0x0035
+struct mgmt_ev_pa_subevent_data_request {
+	uint8_t  instance;
+	uint8_t  subevent_start;
+	uint8_t  subevent_data_count;
+} __packed;
+
+struct mgmt_pa_response {
+	int8_t   tx_power;
+	int8_t   rssi;
+	uint8_t  cte_type;
+	uint8_t  response_slot;
+	uint8_t  data_status;
+	uint8_t  data_len;
+	uint8_t  data[];
+} __packed;
+
+#define MGMT_EV_PA_RESPONSE_REPORT		0x0036
+struct mgmt_ev_pa_response_report {
+	uint8_t  instance;
+	uint8_t  subevent;
+	uint8_t  tx_status;
+	uint8_t  num_responses;
+	uint8_t  responses[];
+} __packed;
+
 static const char *mgmt_op[] = {
 	"<0x0000>",
 	"Read Version",
@@ -1250,6 +1319,9 @@ static const char *mgmt_op[] = {
 	"Mesh Send Cancel",
 	"HCI Cmd Sync",
 	"Load Connection Subrate",
+	"Add Periodic Advertising Parameters",
+	"Add Periodic Advertising Data",
+	"Set Periodic Advertising Subevent Data",
 };
 
 static const char *mgmt_ev[] = {
@@ -1306,6 +1378,8 @@ static const char *mgmt_ev[] = {
 	"Mesh Packet Complete",
 	"Connection Subrate",
 	"Security Level Changed",
+	"Periodic Advertising Subevent Data Request",
+	"Periodic Advertising Response Report",
 };
 
 static const char *mgmt_status[] = {
-- 
2.47.3


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

* [RFC PATCH BlueZ v2 3/9] monitor: Decode PA and PAwR MGMT commands and events
  2026-12-02 12:52 [RFC PATCH BlueZ v2 0/9] Periodic advertising and PAwR over MGMT Roland Schober
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 1/9] doc/mgmt: Add PA and PAwR commands and events Roland Schober
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 2/9] lib/mgmt: Add periodic advertising and PAwR definitions Roland Schober
@ 2026-12-02 12:52 ` Roland Schober
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 4/9] client/mgmt: Fix length of byte arrays with empty entries Roland Schober
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Roland Schober @ 2026-12-02 12:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Roland Schober

Decode Add Periodic Advertising Parameters, Add Periodic Advertising
Data, Set Periodic Advertising Subevent Data and the events Periodic
Advertising Subevent Data Request and Periodic Advertising Response
Report. A train with responses, a request for the data of two
subevents, the answer to it and a response:

@ MGMT Command: Add Periodic.. (0x005d) plen 10  {0x0001} [hci0] 2.872447
        Instance: 1
        Min interval: 318.75 msec (0x00ff)
        Max interval: 318.75 msec (0x00ff)
        Num subevents: 5
        Subevent interval: 60.00 msec (0x30)
        Response slot delay: 10.00 msec (0x08)
        Response slot spacing: 10.000 msec (0x50)
        Num response slots: 5
@ MGMT Event: Periodic Advert.. (0x0035) plen 3  {0x0001} [hci0] 3.329062
        Instance: 1
        Subevent start: 4 (0x04)
        Subevent data count: 2 (0x02)
@ MGMT Command: Set Periodic.. (0x005f) plen 22  {0x0001} [hci0] 3.330232
        Instance: 1
        Num subevents: 2
        Entry 0
          Subevent: 4 (0x04)
          Response slot start: 0
          Response slot count: 5
          Data length: 6
          Data[6]:
        05 ff 59 00 04 03                                ..Y...
        Company: Nordic Semiconductor ASA (89)
          Data[2]:
        04 03                                            ..
        Entry 1
          Subevent: 0 (0x00)
          Response slot start: 0
          Response slot count: 5
          Data length: 6
          Data[6]:
        05 ff 59 00 00 04                                ..Y...
        Company: Nordic Semiconductor ASA (89)
          Data[2]:
        00 04                                            ..
@ MGMT Event: Periodic Adver.. (0x0036) plen 16  {0x0001} [hci0] 4.776838
        Instance: 1
        Subevent: 0 (0x00)
        TX status: Subevent was transmitted (0x00)
        Num responses: 1
        Entry 0
          TX power: not available (0x7f)
          RSSI: -59 dBm (0xc5)
          CTE type: 0xff
          Response slot: 0 (0x00)
          Data status: Complete (0x00)
          Data length: 6
          Data[6]:
        05 ff 59 00 00 18                                ..Y...
        Company: Nordic Semiconductor ASA (89)
          Data[2]:
        00 18                                            ..

Assisted-by: Claude:claude-fable-5-2
---
 monitor/packet.c | 204 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 204 insertions(+)

diff --git a/monitor/packet.c b/monitor/packet.c
index eddf8706a..1ecbe8050 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -18436,6 +18436,99 @@ static void mgmt_hci_cmd_sync_rsp(const void *data, uint16_t size)
 	print_hex_field("Response", data, size);
 }
 
+static void mgmt_add_periodic_adv_params_cmd(const void *data, uint16_t size)
+{
+	const struct mgmt_cp_add_periodic_adv_params *cp = data;
+	uint16_t min_interval = le16_to_cpu(cp->min_interval);
+	uint16_t max_interval = le16_to_cpu(cp->max_interval);
+
+	print_field("Instance: %u", cp->instance);
+	print_field("Min interval: %.2f msec (0x%4.4x)", min_interval * 1.25,
+								min_interval);
+	print_field("Max interval: %.2f msec (0x%4.4x)", max_interval * 1.25,
+								max_interval);
+	print_field("Num subevents: %u", cp->num_subevents);
+	print_field("Subevent interval: %.2f msec (0x%2.2x)",
+			cp->subevent_interval * 1.25, cp->subevent_interval);
+	print_field("Response slot delay: %.2f msec (0x%2.2x)",
+			cp->response_slot_delay * 1.25,
+			cp->response_slot_delay);
+	print_field("Response slot spacing: %.3f msec (0x%2.2x)",
+			cp->response_slot_spacing * 0.125,
+			cp->response_slot_spacing);
+	print_field("Num response slots: %u", cp->num_response_slots);
+}
+
+static void mgmt_instance_rsp(const void *data, uint16_t size)
+{
+	uint8_t instance = get_u8(data);
+
+	print_field("Instance: %u", instance);
+}
+
+static void mgmt_add_periodic_adv_data_cmd(const void *data, uint16_t size)
+{
+	struct iovec iov = { .iov_base = (void *) data, .iov_len = size };
+	const struct mgmt_cp_add_periodic_adv_data *cp;
+
+	cp = util_iov_pull_mem(&iov, sizeof(*cp));
+	if (!cp)
+		return;
+
+	print_field("Instance: %u", cp->instance);
+	print_field("Data length: %u", cp->data_len);
+
+	if (iov.iov_len != cp->data_len) {
+		print_text(COLOR_ERROR, "  invalid packet size");
+		print_hex_field("  Data", iov.iov_base, iov.iov_len);
+		return;
+	}
+
+	print_eir("Data", cp->data, cp->data_len, true);
+}
+
+static void mgmt_set_pa_subevent_data_cmd(const void *data, uint16_t size)
+{
+	struct iovec iov = { .iov_base = (void *) data, .iov_len = size };
+	const struct mgmt_cp_set_pa_subevent_data *cp;
+	const struct mgmt_pa_subevent_data *se;
+	uint8_t i;
+
+	cp = util_iov_pull_mem(&iov, sizeof(*cp));
+	if (!cp)
+		return;
+
+	print_field("Instance: %u", cp->instance);
+	print_field("Num subevents: %u", cp->num_subevents);
+
+	for (i = 0; i < cp->num_subevents; i++) {
+		se = util_iov_pull_mem(&iov, sizeof(*se));
+		if (!se)
+			break;
+
+		print_field("Entry %u", i);
+		print_field("  Subevent: %u (0x%2.2x)", se->subevent,
+							se->subevent);
+		print_field("  Response slot start: %u",
+						se->response_slot_start);
+		print_field("  Response slot count: %u",
+						se->response_slot_count);
+		print_field("  Data length: %u", se->data_len);
+
+		if (!util_iov_pull(&iov, se->data_len))
+			break;
+
+		print_eir("  Data", se->data, se->data_len, true);
+	}
+
+	/* Fewer entries than announced, or octets after the last one */
+	if (i < cp->num_subevents || iov.iov_len) {
+		print_text(COLOR_ERROR, "  invalid packet size");
+		if (iov.iov_len)
+			print_hex_field("  Data", iov.iov_base, iov.iov_len);
+	}
+}
+
 struct mgmt_data {
 	uint16_t opcode;
 	const char *str;
@@ -18719,6 +18812,15 @@ static const struct mgmt_data mgmt_command_table[] = {
 	{ 0x005C, "Load Connection Subrate",
 				mgmt_load_conn_subrate_cmd, 2, false,
 				mgmt_null_rsp, 0, true },
+	{ 0x005D, "Add Periodic Advertising Parameters",
+				mgmt_add_periodic_adv_params_cmd, 10, true,
+				mgmt_instance_rsp, 1, true },
+	{ 0x005E, "Add Periodic Advertising Data",
+				mgmt_add_periodic_adv_data_cmd, 2, false,
+				mgmt_instance_rsp, 1, true },
+	{ 0x005F, "Set Periodic Advertising Subevent Data",
+				mgmt_set_pa_subevent_data_cmd, 2, false,
+				mgmt_instance_rsp, 1, true },
 	{ }
 };
 
@@ -19383,6 +19485,104 @@ static void mgmt_security_level_changed_evt(const void *data, uint16_t size)
 	mgmt_tlv_list_free(tlv_list);
 }
 
+static void mgmt_pa_subevent_data_request_evt(const void *data,
+							uint16_t size)
+{
+	const struct mgmt_ev_pa_subevent_data_request *ev = data;
+
+	print_field("Instance: %u", ev->instance);
+	print_field("Subevent start: %u (0x%2.2x)", ev->subevent_start,
+							ev->subevent_start);
+	print_field("Subevent data count: %u (0x%2.2x)",
+			ev->subevent_data_count, ev->subevent_data_count);
+}
+
+static void mgmt_pa_response_report_evt(const void *data, uint16_t size)
+{
+	struct iovec iov = { .iov_base = (void *) data, .iov_len = size };
+	const struct mgmt_ev_pa_response_report *ev;
+	const struct mgmt_pa_response *rsp;
+	const char *str;
+	uint8_t i;
+
+	ev = util_iov_pull_mem(&iov, sizeof(*ev));
+	if (!ev)
+		return;
+
+	print_field("Instance: %u", ev->instance);
+	print_field("Subevent: %u (0x%2.2x)", ev->subevent, ev->subevent);
+
+	switch (ev->tx_status) {
+	case 0x00:
+		str = "Subevent was transmitted";
+		break;
+	case 0x01:
+		str = "Subevent was not transmitted";
+		break;
+	default:
+		str = "Reserved";
+		break;
+	}
+
+	print_field("TX status: %s (0x%2.2x)", str, ev->tx_status);
+	print_field("Num responses: %u", ev->num_responses);
+
+	for (i = 0; i < ev->num_responses; i++) {
+		rsp = util_iov_pull_mem(&iov, sizeof(*rsp));
+		if (!rsp)
+			break;
+
+		print_field("Entry %u", i);
+
+		if (rsp->tx_power == 0x7f)
+			print_field("  TX power: not available (0x7f)");
+		else
+			print_field("  TX power: %d dBm (0x%2.2x)",
+					rsp->tx_power, (uint8_t) rsp->tx_power);
+
+		if (rsp->rssi == 0x7f)
+			print_field("  RSSI: not available (0x7f)");
+		else
+			print_field("  RSSI: %d dBm (0x%2.2x)", rsp->rssi,
+							(uint8_t) rsp->rssi);
+
+		print_field("  CTE type: 0x%2.2x", rsp->cte_type);
+		print_field("  Response slot: %u (0x%2.2x)",
+				rsp->response_slot, rsp->response_slot);
+
+		switch (rsp->data_status) {
+		case 0x00:
+			str = "Complete";
+			break;
+		case 0x01:
+			str = "Incomplete, more data to come";
+			break;
+		case 0xff:
+			str = "Failed to receive the response";
+			break;
+		default:
+			str = "Reserved";
+			break;
+		}
+
+		print_field("  Data status: %s (0x%2.2x)", str,
+							rsp->data_status);
+		print_field("  Data length: %u", rsp->data_len);
+
+		if (!util_iov_pull(&iov, rsp->data_len))
+			break;
+
+		print_eir("  Data", rsp->data, rsp->data_len, true);
+	}
+
+	/* Fewer responses than announced, or octets after the last one */
+	if (i < ev->num_responses || iov.iov_len) {
+		print_text(COLOR_ERROR, "  invalid packet size");
+		if (iov.iov_len)
+			print_hex_field("  Data", iov.iov_base, iov.iov_len);
+	}
+}
+
 static const struct mgmt_data mgmt_event_table[] = {
 	{ 0x0001, "Command Complete",
 			mgmt_command_complete_evt, 3, false },
@@ -19484,6 +19684,10 @@ static const struct mgmt_data mgmt_event_table[] = {
 			mgmt_conn_subrate_evt, 18, true },
 	{ 0x0034, "Security Level Changed",
 			mgmt_security_level_changed_evt, 8, false },
+	{ 0x0035, "Periodic Advertising Subevent Data Request",
+			mgmt_pa_subevent_data_request_evt, 3, true },
+	{ 0x0036, "Periodic Advertising Response Report",
+			mgmt_pa_response_report_evt, 4, false },
 	{ }
 };
 
-- 
2.47.3


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

* [RFC PATCH BlueZ v2 4/9] client/mgmt: Fix length of byte arrays with empty entries
  2026-12-02 12:52 [RFC PATCH BlueZ v2 0/9] Periodic advertising and PAwR over MGMT Roland Schober
                   ` (2 preceding siblings ...)
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 3/9] monitor: Decode PA and PAwR MGMT commands and events Roland Schober
@ 2026-12-02 12:52 ` Roland Schober
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 5/9] client/mgmt: Add pa-params, pa-data and pawr-serve commands Roland Schober
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Roland Schober @ 2026-12-02 12:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Roland Schober

str2bytearray() counts the empty entries which two separators in a row
or one at the end of the argument leave, although it stores nothing for
them. The length it returns is then larger than the number of octets
given, and with enough empty entries larger than the buffer: hci-cmd
sends octets it was not given, and octets beyond its packet.

Count the octets which are stored.

Fixes: 95e89cd2e4f8 ("client/mgmt: Add hci-cmd command")
Assisted-by: Claude:claude-fable-5-2
---
 client/mgmt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/client/mgmt.c b/client/mgmt.c
index a7069e5bb..bdf1bbfec 100644
--- a/client/mgmt.c
+++ b/client/mgmt.c
@@ -2398,9 +2398,9 @@ static void cmd_set_flags(int argc, char **argv)
 static uint8_t *str2bytearray(char *arg, uint8_t *val, long *val_len)
 {
 	char *entry;
-	long i;
+	long i = 0;
 
-	for (i = 0; (entry = strsep(&arg, " \t")) != NULL; i++) {
+	while ((entry = strsep(&arg, " \t")) != NULL) {
 		long v;
 		char *endptr = NULL;
 
@@ -2418,7 +2418,7 @@ static uint8_t *str2bytearray(char *arg, uint8_t *val, long *val_len)
 			return NULL;
 		}
 
-		val[i] = v;
+		val[i++] = v;
 	}
 
 	*val_len = i;
-- 
2.47.3


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

* [RFC PATCH BlueZ v2 5/9] client/mgmt: Add pa-params, pa-data and pawr-serve commands
  2026-12-02 12:52 [RFC PATCH BlueZ v2 0/9] Periodic advertising and PAwR over MGMT Roland Schober
                   ` (3 preceding siblings ...)
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 4/9] client/mgmt: Fix length of byte arrays with empty entries Roland Schober
@ 2026-12-02 12:52 ` Roland Schober
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 6/9] monitor: Add PAwR HCI definitions Roland Schober
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Roland Schober @ 2026-12-02 12:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Roland Schober

pa-params adds periodic advertising to an instance created with
add-ext-adv-params, with the parameters of Periodic Advertising with
Responses if subevents are given. pa-data sets the data of a periodic
advertising train.

pawr-serve answers the subevent data requests of an instance, with
the data given or with manufacturer data which carries the subevent
and a counter, and prints the response reports. Data which does not
fit into one command is sent in several. It runs until it is stopped
or replaced by another pawr-serve.

Assisted-by: Claude:claude-fable-5-2
---
 client/mgmt.c             | 367 ++++++++++++++++++++++++++++++++++++++
 doc/bluetoothctl-mgmt.rst |  51 ++++++
 2 files changed, 418 insertions(+)

diff --git a/client/mgmt.c b/client/mgmt.c
index bdf1bbfec..e115654b3 100644
--- a/client/mgmt.c
+++ b/client/mgmt.c
@@ -2504,6 +2504,359 @@ static void cmd_hci_cmd(int argc, char **argv)
 	}
 }
 
+static void pa_params_rsp(uint8_t status, uint16_t len, const void *param,
+							void *user_data)
+{
+	const struct mgmt_rp_add_periodic_adv_params *rp = param;
+
+	if (status != 0) {
+		error("Add Periodic Advertising Parameters failed with status "
+				"0x%02x (%s)", status, mgmt_errstr(status));
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	if (len < sizeof(*rp)) {
+		error("Too small (%u bytes) reply", len);
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	print("Periodic advertising set on instance %u", rp->instance);
+
+	bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
+/* A number for a field of a command: all of the argument, in its range */
+static bool parse_num(const char *str, unsigned long max, unsigned long *val)
+{
+	char *endptr = NULL;
+
+	*val = strtoul(str, &endptr, 0);
+	if (!endptr || endptr == str || *endptr != '\0' || *val > max) {
+		error("Invalid value %s (0-%lu)", str, max);
+		return false;
+	}
+
+	return true;
+}
+
+/* The data of a command: the octets of all the arguments which are left */
+static bool parse_data(int argc, char **argv, uint8_t *data, long size,
+								long *len)
+{
+	int i;
+
+	*len = 0;
+
+	for (i = 0; i < argc; i++) {
+		long n = size - *len;
+
+		if (!str2bytearray(argv[i], data + *len, &n))
+			return false;
+
+		*len += n;
+	}
+
+	return true;
+}
+
+static void cmd_pa_params(int argc, char **argv)
+{
+	struct mgmt_cp_add_periodic_adv_params cp;
+	unsigned long val[8];
+	uint16_t index;
+	int i;
+
+	if (argc != 4 && argc != 9) {
+		error("Either none or all five PAwR parameters");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	/* The two intervals have 16 bits, the other parameters 8 */
+	for (i = 1; i < argc; i++) {
+		if (!parse_num(argv[i], i == 2 || i == 3 ? UINT16_MAX :
+						UINT8_MAX, &val[i - 1]))
+			return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	memset(&cp, 0, sizeof(cp));
+	cp.instance = val[0];
+	cp.min_interval = cpu_to_le16(val[1]);
+	cp.max_interval = cpu_to_le16(val[2]);
+
+	if (argc > 4) {
+		cp.num_subevents = val[3];
+		cp.subevent_interval = val[4];
+		cp.response_slot_delay = val[5];
+		cp.response_slot_spacing = val[6];
+		cp.num_response_slots = val[7];
+	}
+
+	index = mgmt_index;
+	if (index == MGMT_INDEX_NONE)
+		index = 0;
+
+	if (mgmt_send(mgmt, MGMT_OP_ADD_PERIODIC_ADV_PARAMS, index,
+			sizeof(cp), &cp, pa_params_rsp, NULL, NULL) == 0) {
+		error("Unable to send Add Periodic Advertising Parameters");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+}
+
+static void pa_data_rsp(uint8_t status, uint16_t len, const void *param,
+							void *user_data)
+{
+	const struct mgmt_rp_add_periodic_adv_data *rp = param;
+
+	if (status != 0) {
+		error("Add Periodic Advertising Data failed with status "
+				"0x%02x (%s)", status, mgmt_errstr(status));
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	if (len < sizeof(*rp)) {
+		error("Too small (%u bytes) reply", len);
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	print("Periodic advertising data set on instance %u", rp->instance);
+
+	bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
+static void cmd_pa_data(int argc, char **argv)
+{
+	uint8_t buf[sizeof(struct mgmt_cp_add_periodic_adv_data) + 252];
+	struct mgmt_cp_add_periodic_adv_data *cp = (void *) buf;
+	unsigned long instance;
+	long data_len;
+	uint16_t index;
+
+	memset(buf, 0, sizeof(buf));
+
+	if (!parse_num(argv[1], UINT8_MAX, &instance) ||
+			!parse_data(argc - 2, argv + 2, cp->data, 252,
+								&data_len))
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+
+	cp->instance = instance;
+	cp->data_len = data_len;
+
+	index = mgmt_index;
+	if (index == MGMT_INDEX_NONE)
+		index = 0;
+
+	if (mgmt_send(mgmt, MGMT_OP_ADD_PERIODIC_ADV_DATA, index,
+			sizeof(*cp) + data_len, cp, pa_data_rsp, NULL,
+			NULL) == 0) {
+		error("Unable to send Add Periodic Advertising Data");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+}
+
+/*
+ * One command has room for 255 octets of parameters and for 15 subevents,
+ * like the HCI command the kernel makes of it.
+ */
+#define PAWR_CMD_SIZE		255
+#define PAWR_CMD_SUBEVENTS	15
+#define PAWR_DATA_SIZE		(PAWR_CMD_SIZE - \
+				sizeof(struct mgmt_cp_set_pa_subevent_data) - \
+				sizeof(struct mgmt_pa_subevent_data))
+
+/* What pawr-serve answers the subevent data requests with */
+static struct {
+	uint8_t instance;
+	uint8_t num_subevents;
+	uint8_t num_response_slots;
+	bool has_data;
+	uint8_t data[PAWR_DATA_SIZE];
+	long data_len;
+	uint8_t counter;
+	unsigned int request_id;
+	unsigned int report_id;
+} pawr;
+
+static void pawr_data_rsp(uint8_t status, uint16_t len, const void *param,
+							void *user_data)
+{
+	if (status != 0)
+		error("Set Periodic Advertising Subevent Data failed with "
+			"status 0x%02x (%s)", status, mgmt_errstr(status));
+}
+
+/*
+ * Not mgmt_send(): it holds a command back until the one before it has its
+ * reply, and the commands which answer one request cannot wait that long.
+ */
+static void pawr_send_data(uint16_t index, const void *buf, size_t len)
+{
+	if (mgmt_send_nowait(mgmt, MGMT_OP_SET_PA_SUBEVENT_DATA, index, len,
+				buf, pawr_data_rsp, NULL, NULL) == 0)
+		error("Unable to send Set Periodic Advertising Subevent Data");
+}
+
+static void pawr_data_request(uint16_t index, uint16_t len, const void *param,
+							void *user_data)
+{
+	const struct mgmt_ev_pa_subevent_data_request *ev = param;
+	uint8_t buf[PAWR_CMD_SIZE];
+	struct mgmt_cp_set_pa_subevent_data *cp = (void *) buf;
+	size_t pos = sizeof(*cp);
+	uint8_t i;
+
+	if (len < sizeof(*ev)) {
+		error("Too small (%u bytes) pa_subevent_data_request event",
+									len);
+		return;
+	}
+
+	if (ev->instance != pawr.instance)
+		return;
+
+	print("hci%u pa_subevent_data_request: instance %u start %u count %u",
+			index, ev->instance, ev->subevent_start,
+			ev->subevent_data_count);
+
+	cp->instance = ev->instance;
+	cp->num_subevents = 0;
+
+	for (i = 0; i < ev->subevent_data_count; i++) {
+		struct mgmt_pa_subevent_data *subevent;
+		uint8_t data[sizeof(pawr.data)];
+		uint8_t data_len = pawr.data_len;
+		uint8_t nr = (ev->subevent_start + i) % pawr.num_subevents;
+
+		/* Without data from the command line: manufacturer data
+		 * with the subevent and a counter.
+		 */
+		if (pawr.has_data) {
+			memcpy(data, pawr.data, data_len);
+		} else {
+			data[0] = 0x05;
+			data[1] = 0xff;
+			data[2] = 0x59;
+			data[3] = 0x00;
+			data[4] = nr;
+			data[5] = pawr.counter++;
+			data_len = 6;
+		}
+
+		/* The command is full: send it and go on with a new one */
+		if (pos + sizeof(*subevent) + data_len > sizeof(buf) ||
+				cp->num_subevents == PAWR_CMD_SUBEVENTS) {
+			pawr_send_data(index, buf, pos);
+			pos = sizeof(*cp);
+			cp->num_subevents = 0;
+		}
+
+		subevent = (void *) (buf + pos);
+		subevent->subevent = nr;
+		subevent->response_slot_start = 0;
+		subevent->response_slot_count = pawr.num_response_slots;
+		subevent->data_len = data_len;
+		memcpy(subevent->data, data, data_len);
+
+		pos += sizeof(*subevent) + data_len;
+		cp->num_subevents++;
+	}
+
+	if (cp->num_subevents)
+		pawr_send_data(index, buf, pos);
+}
+
+static void pawr_response_report(uint16_t index, uint16_t len,
+					const void *param, void *user_data)
+{
+	const struct mgmt_ev_pa_response_report *ev = param;
+	const uint8_t *ptr;
+	uint8_t i;
+
+	if (len < sizeof(*ev)) {
+		error("Too small (%u bytes) pa_response_report event", len);
+		return;
+	}
+
+	if (ev->instance != pawr.instance)
+		return;
+
+	ptr = ev->responses;
+	len -= sizeof(*ev);
+
+	for (i = 0; i < ev->num_responses; i++) {
+		const struct mgmt_pa_response *rsp = (const void *) ptr;
+		char str[2 * UINT8_MAX + 1];
+		uint8_t j;
+
+		if (len < sizeof(*rsp) || len < sizeof(*rsp) + rsp->data_len) {
+			error("Truncated pa_response_report event");
+			return;
+		}
+
+		for (j = 0; j < rsp->data_len; j++)
+			sprintf(str + 2 * j, "%02x", rsp->data[j]);
+		str[2 * rsp->data_len] = '\0';
+
+		print("hci%u pa_response_report: instance %u subevent %u "
+			"tx_status %u slot %u rssi %d status 0x%02x data %s",
+			index, ev->instance, ev->subevent, ev->tx_status,
+			rsp->response_slot, rsp->rssi, rsp->data_status, str);
+
+		ptr += sizeof(*rsp) + rsp->data_len;
+		len -= sizeof(*rsp) + rsp->data_len;
+	}
+}
+
+/* Runs until it is stopped */
+static void cmd_pawr_serve(int argc, char **argv)
+{
+	unsigned long instance, num_subevents, num_response_slots;
+	uint8_t data[sizeof(pawr.data)];
+	long data_len;
+	uint16_t index;
+
+	if (!parse_num(argv[1], UINT8_MAX, &instance) ||
+			!parse_num(argv[2], 128, &num_subevents) ||
+			!parse_num(argv[3], UINT8_MAX, &num_response_slots) ||
+			!parse_data(argc - 4, argv + 4, data, sizeof(data),
+								&data_len))
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+
+	if (!num_subevents) {
+		error("Invalid number of subevents");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	/* A second pawr-serve replaces the first */
+	if (pawr.request_id)
+		mgmt_unregister(mgmt, pawr.request_id);
+
+	if (pawr.report_id)
+		mgmt_unregister(mgmt, pawr.report_id);
+
+	memset(&pawr, 0, sizeof(pawr));
+	pawr.instance = instance;
+	pawr.num_subevents = num_subevents;
+	pawr.num_response_slots = num_response_slots;
+	pawr.has_data = argc > 4;
+	pawr.data_len = data_len;
+	memcpy(pawr.data, data, data_len);
+
+	index = mgmt_index;
+	if (index == MGMT_INDEX_NONE)
+		index = 0;
+
+	pawr.request_id = mgmt_register(mgmt, MGMT_EV_PA_SUBEVENT_DATA_REQUEST,
+					index, pawr_data_request, NULL, NULL);
+	pawr.report_id = mgmt_register(mgmt, MGMT_EV_PA_RESPONSE_REPORT, index,
+					pawr_response_report, NULL, NULL);
+	if (!pawr.request_id || !pawr.report_id) {
+		error("Unable to register for the PAwR events");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	print("Serving subevent data of instance %u", pawr.instance);
+}
+
 /* Wrapper to get the index and opcode to the response callback */
 struct command_data {
 	uint16_t id;
@@ -6354,6 +6707,20 @@ static const struct bt_shell_menu mgmt_menu = {
 		cmd_conn_subrate,	"Load Connection Subrate"	},
 	{ "hci-cmd",		"<opcode> [event] [timeout] [param...]",
 		cmd_hci_cmd,	"Send HCI Command and wait for Event"	},
+	{ "pa-params",		"<instance> <min_interval> <max_interval> "
+				"[num_subevents] [subevent_interval] "
+				"[response_slot_delay] [response_slot_spacing] "
+				"[num_response_slots]",
+		cmd_pa_params,
+			"Add periodic advertising to an instance, with "
+			"responses if it has subevents"			},
+	{ "pa-data",		"<instance> [data...]",
+		cmd_pa_data,
+			"Set the periodic advertising data of an instance" },
+	{ "pawr-serve",		"<instance> <num_subevents> "
+				"<num_response_slots> [data...]",
+		cmd_pawr_serve,
+			"Answer subevent data requests, print responses" },
 	{} },
 };
 
diff --git a/doc/bluetoothctl-mgmt.rst b/doc/bluetoothctl-mgmt.rst
index 91406041c..8e27389ef 100644
--- a/doc/bluetoothctl-mgmt.rst
+++ b/doc/bluetoothctl-mgmt.rst
@@ -1314,6 +1314,57 @@ Load Connection Subrate
 :Example Load subrate for LE random address device:
 	| **> conn-subrate -t 2 AA:BB:CC:DD:EE:FF 16 1600 2 8 0 4 100**
 
+pa-params
+---------
+
+Add periodic advertising to an advertising instance. With the five optional
+parameters it is Periodic Advertising with Responses (PAwR).
+
+:Usage: **> pa-params <instance> <min_interval> <max_interval> [num_subevents]
+	[subevent_interval] [response_slot_delay] [response_slot_spacing]
+	[num_response_slots]**
+:<instance>: Advertising instance, added with add-ext-adv-params before
+:<min_interval>: Minimum periodic advertising interval (units of 1.25 ms)
+:<max_interval>: Maximum periodic advertising interval (units of 1.25 ms)
+:[num_subevents]: Number of subevents of a periodic advertising event
+:[subevent_interval]: Time between two subevents (units of 1.25 ms)
+:[response_slot_delay]: Time from the start of a subevent to its first
+	response slot (units of 1.25 ms)
+:[response_slot_spacing]: Time between two response slots (units of 0.125 ms)
+:[num_response_slots]: Number of response slots of a subevent
+:Example Add periodic advertising with an interval of 100 ms to instance 1:
+	| **> pa-params 1 80 80**
+:Example Add PAwR with 5 subevents of 60 ms and 5 response slots of 10 ms:
+	| **> pa-params 1 255 255 5 48 8 80 5**
+
+pa-data
+-------
+
+Set the periodic advertising data of an advertising instance.
+
+:Usage: **> pa-data <instance> [data...]**
+:<instance>: Advertising instance with periodic advertising
+:[data...]: Octets of the data, none for no data
+:Example Set a manufacturer specific AD structure as data of instance 1:
+	| **> pa-data 1 0x05 0xff 0x59 0x00 0x01 0x02**
+
+pawr-serve
+----------
+
+Answer the subevent data requests of an advertising instance with PAwR, and
+print the responses which are received. It runs until btmgmt is ended, or
+until another pawr-serve replaces it.
+
+:Usage: **> pawr-serve <instance> <num_subevents> <num_response_slots>
+	[data...]**
+:<instance>: Advertising instance with PAwR
+:<num_subevents>: Number of subevents of the instance (1 to 128)
+:<num_response_slots>: Number of response slots to listen to in a subevent
+:[data...]: Octets of the data of every subevent (up to 249). Without it, a
+	manufacturer specific AD structure with the subevent and a counter
+:Example Serve instance 1 with 5 subevents and 5 response slots:
+	| **> pawr-serve 1 5 5**
+
 RESOURCES
 =========
 
-- 
2.47.3


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

* [RFC PATCH BlueZ v2 6/9] monitor: Add PAwR HCI definitions
  2026-12-02 12:52 [RFC PATCH BlueZ v2 0/9] Periodic advertising and PAwR over MGMT Roland Schober
                   ` (4 preceding siblings ...)
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 5/9] client/mgmt: Add pa-params, pa-data and pawr-serve commands Roland Schober
@ 2026-12-02 12:52 ` Roland Schober
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 7/9] emulator/btdev: Keep advertising sets with PA enabled Roland Schober
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Roland Schober @ 2026-12-02 12:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Roland Schober

Add the commands and events of Periodic Advertising with Responses to
bt.h, for the emulator. They are those of "monitor: Decode Periodic
Advertising with Responses", which adds the decoding.

Assisted-by: Claude:claude-fable-5-2
---
 monitor/bt.h | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 174 insertions(+)

diff --git a/monitor/bt.h b/monitor/bt.h
index 59bc90ccd..1231f3e84 100644
--- a/monitor/bt.h
+++ b/monitor/bt.h
@@ -3032,6 +3032,90 @@ struct bt_hci_rsp_le_read_iso_link_quality {
 	uint32_t duplicated_packets;
 } __packed;
 
+#define BT_HCI_CMD_LE_SET_PA_SUBEVENT_DATA	0x2082
+#define BT_HCI_BIT_LE_SET_PA_SUBEVENT_DATA	BT_HCI_CMD_BIT(46, 5)
+struct bt_hci_le_pa_subevent_data {
+	uint8_t  subevent;
+	uint8_t  response_slot_start;
+	uint8_t  response_slot_count;
+	uint8_t  data_len;
+	uint8_t  data[];
+} __packed;
+
+struct bt_hci_cmd_le_set_pa_subevent_data {
+	uint8_t  handle;
+	uint8_t  num_subevents;
+	struct bt_hci_le_pa_subevent_data subevents[];
+} __packed;
+
+struct bt_hci_rsp_le_set_pa_subevent_data {
+	uint8_t  status;
+	uint8_t  handle;
+} __packed;
+
+#define BT_HCI_CMD_LE_SET_PA_RESPONSE_DATA	0x2083
+#define BT_HCI_BIT_LE_SET_PA_RESPONSE_DATA	BT_HCI_CMD_BIT(46, 6)
+struct bt_hci_cmd_le_set_pa_response_data {
+	uint16_t sync_handle;
+	uint16_t request_event;
+	uint8_t  request_subevent;
+	uint8_t  response_subevent;
+	uint8_t  response_slot;
+	uint8_t  data_len;
+	uint8_t  data[];
+} __packed;
+
+struct bt_hci_rsp_le_set_pa_response_data {
+	uint8_t  status;
+	uint16_t sync_handle;
+} __packed;
+
+#define BT_HCI_CMD_LE_SET_PA_SYNC_SUBEVENT	0x2084
+#define BT_HCI_BIT_LE_SET_PA_SYNC_SUBEVENT	BT_HCI_CMD_BIT(46, 7)
+struct bt_hci_cmd_le_set_pa_sync_subevent {
+	uint16_t sync_handle;
+	uint16_t properties;
+	uint8_t  num_subevents;
+	uint8_t  subevents[];
+} __packed;
+
+struct bt_hci_rsp_le_set_pa_sync_subevent {
+	uint8_t  status;
+	uint16_t sync_handle;
+} __packed;
+
+#define BT_HCI_CMD_LE_EXT_CREATE_CONN_V2	0x2085
+#define BT_HCI_BIT_LE_EXT_CREATE_CONN_V2	BT_HCI_CMD_BIT(47, 0)
+struct bt_hci_cmd_le_ext_create_conn_v2 {
+	uint8_t  adv_handle;
+	uint8_t  subevent;
+	uint8_t  filter_policy;
+	uint8_t  own_addr_type;
+	uint8_t  peer_addr_type;
+	uint8_t  peer_addr[6];
+	uint8_t  phys;
+	uint8_t  data[];
+} __packed;
+
+#define BT_HCI_CMD_LE_SET_PA_PARAMS_V2		0x2086
+#define BT_HCI_BIT_LE_SET_PA_PARAMS_V2		BT_HCI_CMD_BIT(47, 1)
+struct bt_hci_cmd_le_set_pa_params_v2 {
+	uint8_t  handle;
+	uint16_t min_interval;
+	uint16_t max_interval;
+	uint16_t properties;
+	uint8_t  num_subevents;
+	uint8_t  subevent_interval;
+	uint8_t  response_slot_delay;
+	uint8_t  response_slot_spacing;
+	uint8_t  num_response_slots;
+} __packed;
+
+struct bt_hci_rsp_le_set_pa_params_v2 {
+	uint8_t  status;
+	uint8_t  handle;
+} __packed;
+
 #define BT_HCI_CMD_LE_READ_ALL_LOCAL_FEATURES	0x2087
 #define BT_HCI_BIT_LE_READ_ALL_LOCAL_FEATURES	BT_HCI_CMD_BIT(47, 2)
 struct bt_hci_rsp_le_read_all_local_features {
@@ -4373,6 +4457,96 @@ struct bt_hci_evt_le_big_info_adv_report {
 	uint8_t  encryption;
 } __packed;
 
+#define BT_HCI_EVT_LE_PA_SYNC_ESTABLISHED_V2	0x24
+struct bt_hci_evt_le_per_sync_established_v2 {
+	uint8_t  status;
+	uint16_t handle;
+	uint8_t  sid;
+	uint8_t  addr_type;
+	uint8_t  addr[6];
+	uint8_t  phy;
+	uint16_t interval;
+	uint8_t  clock_accuracy;
+	uint8_t  num_subevents;
+	uint8_t  subevent_interval;
+	uint8_t  response_slot_delay;
+	uint8_t  response_slot_spacing;
+} __packed;
+
+#define BT_HCI_EVT_LE_PA_REPORT_V2		0x25
+struct bt_hci_le_pa_report_v2 {
+	uint16_t handle;
+	uint8_t  tx_power;
+	int8_t   rssi;
+	uint8_t  cte_type;
+	uint16_t event_counter;
+	uint8_t  subevent;
+	uint8_t  data_status;
+	uint8_t  data_len;
+	uint8_t  data[];
+} __packed;
+
+#define BT_HCI_EVT_LE_PAST_RECEIVED_V2		0x26
+struct bt_hci_evt_le_past_recv_v2 {
+	uint8_t  status;
+	uint16_t handle;
+	uint16_t service_data;
+	uint16_t sync_handle;
+	uint8_t  sid;
+	uint8_t  addr_type;
+	uint8_t  addr[6];
+	uint8_t  phy;
+	uint16_t interval;
+	uint8_t  clock_accuracy;
+	uint8_t  num_subevents;
+	uint8_t  subevent_interval;
+	uint8_t  response_slot_delay;
+	uint8_t  response_slot_spacing;
+} __packed;
+
+#define BT_HCI_EVT_LE_PA_SUBEVENT_DATA_REQUEST	0x27
+struct bt_hci_evt_le_pa_subevent_data_request {
+	uint8_t  handle;
+	uint8_t  subevent_start;
+	uint8_t  subevent_data_count;
+} __packed;
+
+#define BT_HCI_EVT_LE_PA_RESPONSE_REPORT		0x28
+struct bt_hci_le_pa_response {
+	int8_t   tx_power;
+	int8_t   rssi;
+	uint8_t  cte_type;
+	uint8_t  response_slot;
+	uint8_t  data_status;
+	uint8_t  data_len;
+	uint8_t  data[];
+} __packed;
+
+struct bt_hci_evt_le_pa_response_report {
+	uint8_t  handle;
+	uint8_t  subevent;
+	uint8_t  tx_status;
+	uint8_t  num_responses;
+	struct bt_hci_le_pa_response responses[];
+} __packed;
+
+#define BT_HCI_EVT_LE_ENHANCED_CONN_COMPLETE_V2	0x29
+struct bt_hci_evt_le_enhanced_conn_complete_v2 {
+	uint8_t  status;
+	uint16_t handle;
+	uint8_t  role;
+	uint8_t  peer_addr_type;
+	uint8_t  peer_addr[6];
+	uint8_t  local_rpa[6];
+	uint8_t  peer_rpa[6];
+	uint16_t interval;
+	uint16_t latency;
+	uint16_t supv_timeout;
+	uint8_t  clock_accuracy;
+	uint8_t  adv_handle;
+	uint16_t sync_handle;
+} __packed;
+
 #define BT_HCI_EVT_LE_READ_ALL_REMOTE_FEATURES_COMPLETE	0x2B
 struct bt_hci_evt_le_read_all_remote_features_complete {
 	uint8_t  status;
-- 
2.47.3


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

* [RFC PATCH BlueZ v2 7/9] emulator/btdev: Keep advertising sets with PA enabled
  2026-12-02 12:52 [RFC PATCH BlueZ v2 0/9] Periodic advertising and PAwR over MGMT Roland Schober
                   ` (5 preceding siblings ...)
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 6/9] monitor: Add PAwR HCI definitions Roland Schober
@ 2026-12-02 12:52 ` Roland Schober
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 8/9] emulator/btdev: Add PAwR advertiser Roland Schober
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 9/9] mgmt-tester: Add periodic advertising and PAwR tests Roland Schober
  8 siblings, 0 replies; 10+ messages in thread
From: Roland Schober @ 2026-12-02 12:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Roland Schober

LE Remove Advertising Set and LE Clear Advertising Sets are answered
with Command Disallowed while periodic advertising is enabled on the
set, as the specification says. A reset disables periodic advertising.

Assisted-by: Claude:claude-fable-5-2
---
 emulator/btdev.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 1140acd90..c4ade031e 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -266,6 +266,7 @@ struct btdev {
 	uint16_t le_pa_max_interval;
 	uint8_t  le_pa_data_len;
 	uint8_t  le_pa_data[MAX_PA_DATA_LEN];
+	uint8_t  le_pa_handle;
 	uint8_t  le_ltk[16];
 	uint8_t  hdt_def_mic_len;
 	uint8_t  hdt_def_format;
@@ -693,6 +694,8 @@ static void btdev_reset(struct btdev *btdev)
 		btdev->inquiry_id = 0;
 	}
 
+	btdev->le_pa_enable = 0x00;
+
 	queue_remove_all(btdev->conns, NULL, NULL, conn_remove);
 	queue_remove_all(btdev->le_ext_adv, NULL, NULL, le_ext_adv_free);
 	queue_remove_all(btdev->le_per_adv, NULL, NULL, free);
@@ -5981,7 +5984,8 @@ static int cmd_remove_adv_set(struct btdev *dev, const void *data,
 		return 0;
 	}
 
-	if (ext_adv->enable) {
+	if (ext_adv->enable || (dev->le_pa_enable &&
+				dev->le_pa_handle == cmd->handle)) {
 		status = BT_HCI_ERR_COMMAND_DISALLOWED;
 		cmd_complete(dev, BT_HCI_CMD_LE_REMOVE_ADV_SET, &status,
 						sizeof(status));
@@ -6003,6 +6007,13 @@ static int cmd_clear_adv_sets(struct btdev *dev, const void *data,
 	const struct queue_entry *entry;
 	uint8_t status = BT_HCI_ERR_SUCCESS;
 
+	if (dev->le_pa_enable) {
+		status = BT_HCI_ERR_COMMAND_DISALLOWED;
+		cmd_complete(dev, BT_HCI_CMD_LE_CLEAR_ADV_SETS, &status,
+							sizeof(status));
+		return 0;
+	}
+
 	for (entry = queue_get_entries(dev->le_ext_adv); entry;
 							entry = entry->next) {
 		struct le_ext_adv *ext_adv = entry->data;
@@ -6036,6 +6047,7 @@ static int cmd_set_pa_params(struct btdev *dev, const void *data,
 		dev->le_pa_properties = le16_to_cpu(cmd->properties);
 		dev->le_pa_min_interval = cmd->min_interval;
 		dev->le_pa_max_interval = cmd->max_interval;
+		dev->le_pa_handle = cmd->handle;
 	}
 
 	cmd_complete(dev, BT_HCI_CMD_LE_SET_PA_PARAMS, &status,
-- 
2.47.3


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

* [RFC PATCH BlueZ v2 8/9] emulator/btdev: Add PAwR advertiser
  2026-12-02 12:52 [RFC PATCH BlueZ v2 0/9] Periodic advertising and PAwR over MGMT Roland Schober
                   ` (6 preceding siblings ...)
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 7/9] emulator/btdev: Keep advertising sets with PA enabled Roland Schober
@ 2026-12-02 12:52 ` Roland Schober
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 9/9] mgmt-tester: Add periodic advertising and PAwR tests Roland Schober
  8 siblings, 0 replies; 10+ messages in thread
From: Roland Schober @ 2026-12-02 12:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Roland Schober

Add the advertiser side of Periodic Advertising with Responses to
controllers of version 6.0 and later:

 - the PAwR Advertiser feature;
 - LE Set Periodic Advertising Parameters [v2], which checks the
   subevent parameters against each other and against the interval;
 - LE Periodic Advertising Subevent Data Request, sent once per
   periodic advertising interval for all subevents while the train is
   enabled;
 - LE Set Periodic Advertising Subevent Data, which takes the data of
   a subevent once per request. Data which was not asked for is
   refused with Command Disallowed: before the first request, a second
   time for one subevent, and for a subevent the train does not have.

LE Set Periodic Advertising Data is refused for a set with subevents.
Nothing is transmitted and no responses are reported, so the command
never answers Too Late or Too Early.

Assisted-by: Claude:claude-fable-5-2
---
 emulator/btdev.c | 292 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 291 insertions(+), 1 deletion(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index c4ade031e..baec3e996 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -267,6 +267,11 @@ struct btdev {
 	uint8_t  le_pa_data_len;
 	uint8_t  le_pa_data[MAX_PA_DATA_LEN];
 	uint8_t  le_pa_handle;
+	uint8_t  le_pa_num_subevents;
+	uint8_t  le_pa_num_rsp_slots;
+	bool     le_pa_data_requested;
+	uint8_t  le_pa_subevents[16];	/* Subevents which wait for data */
+	unsigned int le_pa_subevent_id;
 	uint8_t  le_ltk[16];
 	uint8_t  hdt_def_mic_len;
 	uint8_t  hdt_def_format;
@@ -694,7 +699,13 @@ static void btdev_reset(struct btdev *btdev)
 		btdev->inquiry_id = 0;
 	}
 
+	if (btdev->le_pa_subevent_id > 0) {
+		timeout_remove(btdev->le_pa_subevent_id);
+		btdev->le_pa_subevent_id = 0;
+	}
+
 	btdev->le_pa_enable = 0x00;
+	btdev->le_pa_num_subevents = 0;
 
 	queue_remove_all(btdev->conns, NULL, NULL, conn_remove);
 	queue_remove_all(btdev->le_ext_adv, NULL, NULL, le_ext_adv_free);
@@ -5995,6 +6006,10 @@ static int cmd_remove_adv_set(struct btdev *dev, const void *data,
 	queue_remove(dev->le_ext_adv, ext_adv);
 	free(ext_adv);
 
+	/* The subevents go with their set */
+	if (dev->le_pa_handle == cmd->handle)
+		dev->le_pa_num_subevents = 0;
+
 	cmd_complete(dev, BT_HCI_CMD_LE_REMOVE_ADV_SET, &status,
 							sizeof(status));
 
@@ -6027,6 +6042,7 @@ static int cmd_clear_adv_sets(struct btdev *dev, const void *data,
 	}
 
 	queue_remove_all(dev->le_ext_adv, NULL, NULL, le_ext_adv_free);
+	dev->le_pa_num_subevents = 0;
 
 	cmd_complete(dev, BT_HCI_CMD_LE_CLEAR_ADV_SETS, &status,
 							sizeof(status));
@@ -6048,6 +6064,7 @@ static int cmd_set_pa_params(struct btdev *dev, const void *data,
 		dev->le_pa_min_interval = cmd->min_interval;
 		dev->le_pa_max_interval = cmd->max_interval;
 		dev->le_pa_handle = cmd->handle;
+		dev->le_pa_num_subevents = 0;
 	}
 
 	cmd_complete(dev, BT_HCI_CMD_LE_SET_PA_PARAMS, &status,
@@ -6055,6 +6072,236 @@ static int cmd_set_pa_params(struct btdev *dev, const void *data,
 	return 0;
 }
 
+/*
+ * The intervals and the response slot delay are in units of 1.25 ms, the
+ * response slot spacing in units of 0.125 ms.
+ */
+static bool pa_params_v2_valid(const struct bt_hci_cmd_le_set_pa_params_v2 *cmd)
+{
+	uint16_t min_interval = le16_to_cpu(cmd->min_interval);
+	uint16_t max_interval = le16_to_cpu(cmd->max_interval);
+	uint16_t subevent_interval = cmd->subevent_interval;
+
+	if (min_interval < 0x0006 || min_interval > max_interval ||
+						cmd->num_subevents > 0x80)
+		return false;
+
+	/* Without subevents the other parameters are ignored */
+	if (!cmd->num_subevents)
+		return true;
+
+	/* A single subevent has the periodic advertising interval */
+	if (cmd->num_subevents == 1)
+		subevent_interval = max_interval;
+	else if (subevent_interval < 0x06 ||
+			cmd->num_subevents * subevent_interval > min_interval)
+		return false;
+
+	if (!cmd->num_response_slots)
+		return true;
+
+	/* The response slots follow the packet and end with the subevent */
+	if (!cmd->response_slot_delay ||
+			cmd->response_slot_delay >= subevent_interval)
+		return false;
+
+	if (cmd->num_response_slots > 1 &&
+			(cmd->response_slot_spacing < 0x02 ||
+			cmd->response_slot_spacing * cmd->num_response_slots >
+			10 * (subevent_interval - cmd->response_slot_delay)))
+		return false;
+
+	return true;
+}
+
+static int cmd_set_pa_params_v2(struct btdev *dev, const void *data,
+							uint8_t len)
+{
+	const struct bt_hci_cmd_le_set_pa_params_v2 *cmd = data;
+	struct bt_hci_rsp_le_set_pa_params_v2 rsp;
+
+	memset(&rsp, 0, sizeof(rsp));
+	rsp.handle = cmd->handle;
+
+	if (!queue_find(dev->le_ext_adv, match_ext_adv_handle,
+					UINT_TO_PTR(cmd->handle))) {
+		rsp.status = BT_HCI_ERR_UNKNOWN_ADVERTISING_ID;
+		goto done;
+	}
+
+	if (dev->le_pa_enable) {
+		rsp.status = BT_HCI_ERR_COMMAND_DISALLOWED;
+		goto done;
+	}
+
+	if (!pa_params_v2_valid(cmd)) {
+		rsp.status = BT_HCI_ERR_INVALID_PARAMETERS;
+		goto done;
+	}
+
+	dev->le_pa_properties = le16_to_cpu(cmd->properties);
+	dev->le_pa_min_interval = cmd->min_interval;
+	dev->le_pa_max_interval = cmd->max_interval;
+	dev->le_pa_handle = cmd->handle;
+	dev->le_pa_num_subevents = cmd->num_subevents;
+	dev->le_pa_num_rsp_slots = cmd->num_response_slots;
+
+done:
+	cmd_complete(dev, BT_HCI_CMD_LE_SET_PA_PARAMS_V2, &rsp, sizeof(rsp));
+
+	return 0;
+}
+
+static int cmd_set_pa_subevent_data(struct btdev *dev, const void *data,
+							uint8_t len)
+{
+	struct iovec iov = { .iov_base = (void *) data, .iov_len = len };
+	const struct bt_hci_cmd_le_set_pa_subevent_data *cmd;
+	const struct bt_hci_le_pa_subevent_data *se;
+	struct bt_hci_rsp_le_set_pa_subevent_data rsp;
+	uint8_t seen[sizeof(dev->le_pa_subevents)] = {};
+	uint8_t i;
+
+	memset(&rsp, 0, sizeof(rsp));
+
+	cmd = util_iov_pull_mem(&iov, sizeof(*cmd));
+	if (!cmd)
+		return -EINVAL;
+
+	rsp.handle = cmd->handle;
+
+	if (!queue_find(dev->le_ext_adv, match_ext_adv_handle,
+					UINT_TO_PTR(cmd->handle))) {
+		rsp.status = BT_HCI_ERR_UNKNOWN_ADVERTISING_ID;
+		goto done;
+	}
+
+	/* Only a running train with subevents asks for data */
+	if (!dev->le_pa_enable || dev->le_pa_handle != cmd->handle ||
+						!dev->le_pa_num_subevents) {
+		rsp.status = BT_HCI_ERR_COMMAND_DISALLOWED;
+		goto done;
+	}
+
+	if (!cmd->num_subevents || cmd->num_subevents > 0x0f) {
+		rsp.status = BT_HCI_ERR_INVALID_PARAMETERS;
+		goto done;
+	}
+
+	for (i = 0; i < cmd->num_subevents; i++) {
+		se = util_iov_pull_mem(&iov, sizeof(*se));
+		if (!se || !util_iov_pull(&iov, se->data_len)) {
+			rsp.status = BT_HCI_ERR_INVALID_PARAMETERS;
+			goto done;
+		}
+
+		/* Outside of the subevents which are asked for */
+		if (se->subevent >= dev->le_pa_num_subevents) {
+			rsp.status = BT_HCI_ERR_COMMAND_DISALLOWED;
+			goto done;
+		}
+
+		if (se->response_slot_start + se->response_slot_count >
+						dev->le_pa_num_rsp_slots) {
+			rsp.status = BT_HCI_ERR_INVALID_PARAMETERS;
+			goto done;
+		}
+
+		/* A subevent is named once */
+		if (seen[se->subevent / 8] & BIT(se->subevent % 8)) {
+			rsp.status = BT_HCI_ERR_INVALID_PARAMETERS;
+			goto done;
+		}
+
+		seen[se->subevent / 8] |= BIT(se->subevent % 8);
+	}
+
+	if (iov.iov_len) {
+		rsp.status = BT_HCI_ERR_INVALID_PARAMETERS;
+		goto done;
+	}
+
+	/* Data is taken once for each subevent asked for: not before the
+	 * first request, and not a second time in one periodic advertising
+	 * event.
+	 */
+	iov.iov_base = (void *) cmd->subevents;
+	iov.iov_len = len - sizeof(*cmd);
+
+	for (i = 0; i < cmd->num_subevents; i++) {
+		se = util_iov_pull_mem(&iov, sizeof(*se));
+		util_iov_pull(&iov, se->data_len);
+
+		if (!dev->le_pa_data_requested ||
+				!(dev->le_pa_subevents[se->subevent / 8] &
+						BIT(se->subevent % 8))) {
+			rsp.status = BT_HCI_ERR_COMMAND_DISALLOWED;
+			goto done;
+		}
+	}
+
+	iov.iov_base = (void *) cmd->subevents;
+	iov.iov_len = len - sizeof(*cmd);
+
+	for (i = 0; i < cmd->num_subevents; i++) {
+		se = util_iov_pull_mem(&iov, sizeof(*se));
+		util_iov_pull(&iov, se->data_len);
+
+		dev->le_pa_subevents[se->subevent / 8] &=
+						~BIT(se->subevent % 8);
+	}
+
+done:
+	cmd_complete(dev, BT_HCI_CMD_LE_SET_PA_SUBEVENT_DATA, &rsp,
+							sizeof(rsp));
+
+	return 0;
+}
+
+/* Ask the host for the data of all subevents, once per periodic advertising
+ * interval.
+ */
+static bool pa_subevent_data_request(void *user_data)
+{
+	struct btdev *dev = user_data;
+	struct bt_hci_evt_le_pa_subevent_data_request ev;
+	uint8_t start = 0;
+
+	if (!dev->le_pa_enable || !dev->le_pa_num_subevents) {
+		dev->le_pa_subevent_id = 0;
+		return false;
+	}
+
+	/* LE Periodic Advertising Subevent Data Request event */
+	if (!(dev->le_event_mask[4] & 0x40))
+		return true;
+
+	/* Ask for no more than one command can answer, 15 subevents */
+	while (start < dev->le_pa_num_subevents) {
+		uint8_t count = dev->le_pa_num_subevents - start;
+		uint8_t i;
+
+		if (count > 0x0f)
+			count = 0x0f;
+
+		for (i = start; i < start + count; i++)
+			dev->le_pa_subevents[i / 8] |= BIT(i % 8);
+
+		dev->le_pa_data_requested = true;
+
+		ev.handle = dev->le_pa_handle;
+		ev.subevent_start = start;
+		ev.subevent_data_count = count;
+
+		le_meta_event(dev, BT_HCI_EVT_LE_PA_SUBEVENT_DATA_REQUEST,
+							&ev, sizeof(ev));
+
+		start += count;
+	}
+
+	return true;
+}
+
 static int cmd_set_pa_data(struct btdev *dev, const void *data,
 							uint8_t len)
 {
@@ -6062,6 +6309,14 @@ static int cmd_set_pa_data(struct btdev *dev, const void *data,
 	uint8_t status = BT_HCI_ERR_SUCCESS;
 	uint8_t data_len = cmd->data_len;
 
+	/* A train with subevents carries its data in the subevents */
+	if (dev->le_pa_num_subevents && dev->le_pa_handle == cmd->handle) {
+		status = BT_HCI_ERR_COMMAND_DISALLOWED;
+		cmd_complete(dev, BT_HCI_CMD_LE_SET_PA_DATA, &status,
+							sizeof(status));
+		return 0;
+	}
+
 	if (data_len > MAX_PA_DATA_LEN)
 		data_len = MAX_PA_DATA_LEN;
 
@@ -6268,6 +6523,28 @@ static bool match_remote(const void *data, const void *match_data)
 	return pa->remote == remote;
 }
 
+/* Start, or stop, asking the host for subevent data */
+static void pa_subevent_restart(struct btdev *dev)
+{
+	if (dev->le_pa_subevent_id > 0) {
+		timeout_remove(dev->le_pa_subevent_id);
+		dev->le_pa_subevent_id = 0;
+	}
+
+	dev->le_pa_data_requested = false;
+	memset(dev->le_pa_subevents, 0, sizeof(dev->le_pa_subevents));
+
+	if (dev->le_pa_enable && dev->le_pa_num_subevents) {
+		/* The interval is in units of 1.25 ms */
+		unsigned int msec = le16_to_cpu(dev->le_pa_min_interval) *
+								5 / 4;
+
+		dev->le_pa_subevent_id = timeout_add(msec,
+						pa_subevent_data_request,
+						dev, NULL);
+	}
+}
+
 static int cmd_set_pa_enable(struct btdev *dev, const void *data, uint8_t len)
 {
 	const struct bt_hci_cmd_le_set_pa_enable *cmd = data;
@@ -6284,6 +6561,10 @@ static int cmd_set_pa_enable(struct btdev *dev, const void *data, uint8_t len)
 	cmd_complete(dev, BT_HCI_CMD_LE_SET_PA_ENABLE, &status,
 							sizeof(status));
 
+	/* A command which is refused leaves the train as it is */
+	if (status == BT_HCI_ERR_SUCCESS)
+		pa_subevent_restart(dev);
+
 	for (i = 0; i < MAX_BTDEV_ENTRIES; i++) {
 		struct btdev *remote = btdev_list[i];
 
@@ -8362,7 +8643,10 @@ done:
 	CMD(BT_HCI_CMD_LE_READ_ALL_REMOTE_FEATURES, \
 			cmd_le_read_all_remote_features, NULL), \
 	CMD(BT_HCI_CMD_LE_SET_HOST_FEATURE_V2, \
-			cmd_set_host_feature_v2, NULL)
+			cmd_set_host_feature_v2, NULL), \
+	CMD(BT_HCI_CMD_LE_SET_PA_PARAMS_V2, cmd_set_pa_params_v2, NULL), \
+	CMD(BT_HCI_CMD_LE_SET_PA_SUBEVENT_DATA, cmd_set_pa_subevent_data, \
+			NULL)
 
 static const struct btdev_cmd cmd_le_6_0[] = {
 	CMD_COMMON_ALL,
@@ -8382,6 +8666,8 @@ static void set_le_60_commands(struct btdev *btdev)
 	btdev->commands[47] |= BIT(2);	/* LE Read All Local Features */
 	btdev->commands[47] |= BIT(3);	/* LE Read All Remote Features */
 	btdev->commands[47] |= BIT(4);	/* LE Set Host Feature V2 */
+	btdev->commands[46] |= BIT(5);	/* LE Set PA Subevent Data */
+	btdev->commands[47] |= BIT(1);	/* LE Set PA Parameters v2 */
 	btdev->cmds = cmd_le_6_0;
 }
 
@@ -9159,6 +9445,7 @@ static void set_bredrle_features(struct btdev *btdev)
 
 	if (btdev->type >= BTDEV_TYPE_BREDRLE60) {
 		btdev->version = 0x0e;
+		btdev->le_features[5] |= BIT(3); /* PAwR Advertiser */
 		btdev->le_features[7] |= BIT(7); /* LL Extended Features */
 	}
 
@@ -9381,6 +9668,9 @@ void btdev_destroy(struct btdev *btdev)
 	if (btdev->inquiry_id > 0)
 		timeout_remove(btdev->inquiry_id);
 
+	if (btdev->le_pa_subevent_id > 0)
+		timeout_remove(btdev->le_pa_subevent_id);
+
 	bt_crypto_unref(btdev->crypto);
 	del_btdev(btdev);
 
-- 
2.47.3


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

* [RFC PATCH BlueZ v2 9/9] mgmt-tester: Add periodic advertising and PAwR tests
  2026-12-02 12:52 [RFC PATCH BlueZ v2 0/9] Periodic advertising and PAwR over MGMT Roland Schober
                   ` (7 preceding siblings ...)
  2026-12-02 12:52 ` [RFC PATCH BlueZ v2 8/9] emulator/btdev: Add PAwR advertiser Roland Schober
@ 2026-12-02 12:52 ` Roland Schober
  8 siblings, 0 replies; 10+ messages in thread
From: Roland Schober @ 2026-12-02 12:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Roland Schober

Add tests for Add Periodic Advertising Parameters, Add Periodic
Advertising Data, Set Periodic Advertising Subevent Data and the
Periodic Advertising Subevent Data Request event:

 - the HCI commands sent for plain periodic advertising and for
   Periodic Advertising with Responses, on a second instance as well;
 - parameters and states which are refused, and controllers without
   the features;
 - Remove Advertising and Set Powered off with a train running, where
   periodic advertising has to be disabled before the advertising set
   is removed;
 - subevent data sent before the controller asked for it, in answer to
   its request, in two commands at once, twice for one subevent and
   for a subevent the train does not have.

Assisted-by: Claude:claude-fable-5-2
---
 tools/mgmt-tester.c | 1068 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 1068 insertions(+)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 18dbd3f89..1a897ff7c 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -8191,6 +8191,946 @@ static void setup_command_generic(const void *test_data)
 	}
 }
 
+/* Periodic advertising and Periodic Advertising with Responses over MGMT */
+static const uint8_t pa_ext_adv_params[] = {
+	0x01, /* instance */
+	0x80, 0x00, 0x00, 0x00, /* flags: secondary channel LE 1M */
+	0x00, 0x00, /* duration */
+	0x00, 0x00, /* timeout */
+	0x00, 0x00, 0x00, 0x00, /* min_interval */
+	0x00, 0x00, 0x00, 0x00, /* max_interval */
+	0x7f, /* tx_power */
+};
+
+static const uint8_t pa_ext_adv_params_2[] = {
+	0x02, /* instance */
+	0x80, 0x00, 0x00, 0x00, /* flags: secondary channel LE 1M */
+	0x00, 0x00, /* duration */
+	0x00, 0x00, /* timeout */
+	0x00, 0x00, 0x00, 0x00, /* min_interval */
+	0x00, 0x00, 0x00, 0x00, /* max_interval */
+	0x7f, /* tx_power */
+};
+
+static const uint8_t pa_ext_adv_params_conn[] = {
+	0x01, /* instance */
+	0x81, 0x00, 0x00, 0x00, /* flags: connectable, LE 1M */
+	0x00, 0x00, /* duration */
+	0x00, 0x00, /* timeout */
+	0x00, 0x00, 0x00, 0x00, /* min_interval */
+	0x00, 0x00, 0x00, 0x00, /* max_interval */
+	0x7f, /* tx_power */
+};
+
+static const uint8_t pa_ext_adv_params_legacy[] = {
+	0x01, /* instance */
+	0x00, 0x00, 0x00, 0x00, /* flags: none, legacy PDUs */
+	0x00, 0x00, /* duration */
+	0x00, 0x00, /* timeout */
+	0x00, 0x00, 0x00, 0x00, /* min_interval */
+	0x00, 0x00, 0x00, 0x00, /* max_interval */
+	0x7f, /* tx_power */
+};
+
+static const uint8_t pa_ext_adv_data[] = {
+	0x01, /* instance */
+	0x04, /* Ad data len */
+	0x00, /* Scan response data len */
+	0x03, /* Section length */
+	0x19, /* GAP Appearance */
+	0x01,
+	0x23,
+};
+
+static const uint8_t pa_ext_adv_data_2[] = {
+	0x02, /* instance */
+	0x04, /* Ad data len */
+	0x00, /* Scan response data len */
+	0x03, /* Section length */
+	0x19, /* GAP Appearance */
+	0x01,
+	0x23,
+};
+
+static const uint8_t pa_instance_1[] = { 0x01 };
+static const uint8_t pa_instance_2[] = { 0x02 };
+static const uint8_t pa_instance_all[] = { 0x00 };
+
+static const uint8_t pa_params[] = {
+	0x01, /* instance */
+	0x50, 0x00, /* min_interval: 100 ms */
+	0x50, 0x00, /* max_interval */
+	0x00, /* num_subevents */
+	0x00, /* subevent_interval */
+	0x00, /* response_slot_delay */
+	0x00, /* response_slot_spacing */
+	0x00, /* num_response_slots */
+};
+
+static const uint8_t pa_params_2[] = {
+	0x02, /* instance */
+	0x50, 0x00, /* min_interval: 100 ms */
+	0x50, 0x00, /* max_interval */
+	0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+static const uint8_t pa_params_short[] = {
+	0x01, /* instance */
+	0x05, 0x00, /* min_interval: below 7.5 ms */
+	0x50, 0x00, /* max_interval */
+	0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+static const uint8_t pa_params_min_max[] = {
+	0x01, /* instance */
+	0x51, 0x00, /* min_interval: above the maximum */
+	0x50, 0x00, /* max_interval */
+	0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+/* An interval which leaves time to answer a data request, also on a slow
+ * machine: the controller asks again with every interval.
+ */
+static const uint8_t pawr_params[] = {
+	0x01, /* instance */
+	0x40, 0x01, /* min_interval: 400 ms */
+	0x40, 0x01, /* max_interval */
+	0x05, /* num_subevents */
+	0x06, /* subevent_interval: 7.5 ms */
+	0x02, /* response_slot_delay: 2.5 ms */
+	0x08, /* response_slot_spacing: 1 ms */
+	0x05, /* num_response_slots */
+};
+
+/* The first data request comes after one interval: time to send data which
+ * was not asked for
+ */
+static const uint8_t pawr_params_slow[] = {
+	0x01, /* instance */
+	0x40, 0x06, /* min_interval: 2 s */
+	0x40, 0x06, /* max_interval */
+	0x05, /* num_subevents */
+	0x06, /* subevent_interval: 7.5 ms */
+	0x02, /* response_slot_delay: 2.5 ms */
+	0x08, /* response_slot_spacing: 1 ms */
+	0x05, /* num_response_slots */
+};
+
+static const uint8_t pawr_params_subevents[] = {
+	0x01, /* instance */
+	0x50, 0x00, /* min_interval */
+	0x50, 0x00, /* max_interval */
+	0x81, /* num_subevents: more than 128 */
+	0x06, 0x02, 0x08, 0x05,
+};
+
+static const uint8_t hci_pa_params[] = {
+	0x01, /* handle */
+	0x50, 0x00, /* min_interval */
+	0x50, 0x00, /* max_interval */
+	0x00, 0x00, /* properties */
+};
+
+static const uint8_t hci_pa_params_2[] = {
+	0x02, /* handle */
+	0x50, 0x00, /* min_interval */
+	0x50, 0x00, /* max_interval */
+	0x00, 0x00, /* properties */
+};
+
+static const uint8_t hci_pa_params_v2[] = {
+	0x01, /* handle */
+	0x40, 0x01, /* min_interval */
+	0x40, 0x01, /* max_interval */
+	0x00, 0x00, /* properties */
+	0x05, /* num_subevents */
+	0x06, /* subevent_interval */
+	0x02, /* response_slot_delay */
+	0x08, /* response_slot_spacing */
+	0x05, /* num_response_slots */
+};
+
+static const uint8_t hci_pa_enable[] = { 0x01, 0x01 };
+static const uint8_t hci_pa_enable_2[] = { 0x01, 0x02 };
+static const uint8_t hci_pa_disable[] = { 0x00, 0x01 };
+static const uint8_t hci_pa_remove_set[] = { 0x01 };
+
+static const uint8_t pa_data[] = {
+	0x01, /* instance */
+	0x04, /* data_len */
+	0x03, 0xff, 0x59, 0x00, /* Manufacturer data */
+};
+
+static const uint8_t pa_data_len[] = {
+	0x01, /* instance */
+	0x05, /* data_len: one more than there is */
+	0x03, 0xff, 0x59, 0x00,
+};
+
+static const uint8_t hci_pa_data[] = {
+	0x01, /* handle */
+	0x03, /* operation: complete */
+	0x04, /* data_len */
+	0x03, 0xff, 0x59, 0x00,
+};
+
+static const uint8_t pa_subevent_data_0[] = {
+	0x01, /* instance */
+	0x01, /* num_subevents */
+	0x00, /* subevent */
+	0x00, /* response_slot_start */
+	0x05, /* response_slot_count */
+	0x04, /* data_len */
+	0x03, 0xff, 0x59, 0x00,
+};
+
+static const uint8_t pa_subevent_data_1[] = {
+	0x01, /* instance */
+	0x01, /* num_subevents */
+	0x01, /* subevent */
+	0x00, /* response_slot_start */
+	0x05, /* response_slot_count */
+	0x04, /* data_len */
+	0x03, 0xff, 0x59, 0x01,
+};
+
+static const uint8_t pa_subevent_data_5[] = {
+	0x01, /* instance */
+	0x01, /* num_subevents */
+	0x05, /* subevent */
+	0x00, /* response_slot_start */
+	0x05, /* response_slot_count */
+	0x04, /* data_len */
+	0x03, 0xff, 0x59, 0x05,
+};
+
+static const uint8_t hci_pa_subevent_data_0[] = {
+	0x01, /* handle */
+	0x01, /* num_subevents */
+	0x00, /* subevent */
+	0x00, /* response_slot_start */
+	0x05, /* response_slot_count */
+	0x04, /* data_len */
+	0x03, 0xff, 0x59, 0x00,
+};
+
+static const uint8_t pa_subevent_data_none[] = {
+	0x01, /* instance */
+	0x00, /* num_subevents */
+};
+
+static const uint8_t pa_subevent_data_short[] = {
+	0x01, /* instance */
+	0x01, /* num_subevents */
+	0x00, 0x00, 0x05,
+	0x05, /* data_len: one more than there is */
+	0x03, 0xff, 0x59, 0x00,
+};
+
+static const uint8_t pa_subevent_data_long[] = {
+	0x01, /* instance */
+	0x01, /* num_subevents */
+	0x00, 0x00, 0x05,
+	0x04, /* data_len */
+	0x03, 0xff, 0x59, 0x00,
+	0x00, /* an octet after the last entry */
+};
+
+static const struct setup_mgmt_cmd pa_setup_instance[] = {
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_PARAMS,
+		.send_param = pa_ext_adv_params,
+		.send_len = sizeof(pa_ext_adv_params),
+	},
+};
+
+static const struct setup_mgmt_cmd pa_setup_instance_conn[] = {
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_PARAMS,
+		.send_param = pa_ext_adv_params_conn,
+		.send_len = sizeof(pa_ext_adv_params_conn),
+	},
+};
+
+static const struct setup_mgmt_cmd pa_setup_instance_legacy[] = {
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_PARAMS,
+		.send_param = pa_ext_adv_params_legacy,
+		.send_len = sizeof(pa_ext_adv_params_legacy),
+	},
+};
+
+static const struct setup_mgmt_cmd pa_setup_instances[] = {
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_PARAMS,
+		.send_param = pa_ext_adv_params,
+		.send_len = sizeof(pa_ext_adv_params),
+	},
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_PARAMS,
+		.send_param = pa_ext_adv_params_2,
+		.send_len = sizeof(pa_ext_adv_params_2),
+	},
+};
+
+static const struct setup_mgmt_cmd pa_setup_periodic[] = {
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_PARAMS,
+		.send_param = pa_ext_adv_params,
+		.send_len = sizeof(pa_ext_adv_params),
+	},
+	{
+		.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+		.send_param = pa_params,
+		.send_len = sizeof(pa_params),
+	},
+};
+
+static const struct setup_mgmt_cmd pa_setup_train[] = {
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_PARAMS,
+		.send_param = pa_ext_adv_params,
+		.send_len = sizeof(pa_ext_adv_params),
+	},
+	{
+		.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+		.send_param = pa_params,
+		.send_len = sizeof(pa_params),
+	},
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_DATA,
+		.send_param = pa_ext_adv_data,
+		.send_len = sizeof(pa_ext_adv_data),
+	},
+};
+
+/* Instance 1 advertises, instance 2 has the periodic advertising train */
+static const struct setup_mgmt_cmd pa_setup_trains[] = {
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_PARAMS,
+		.send_param = pa_ext_adv_params,
+		.send_len = sizeof(pa_ext_adv_params),
+	},
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_DATA,
+		.send_param = pa_ext_adv_data,
+		.send_len = sizeof(pa_ext_adv_data),
+	},
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_PARAMS,
+		.send_param = pa_ext_adv_params_2,
+		.send_len = sizeof(pa_ext_adv_params_2),
+	},
+	{
+		.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+		.send_param = pa_params_2,
+		.send_len = sizeof(pa_params_2),
+	},
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_DATA,
+		.send_param = pa_ext_adv_data_2,
+		.send_len = sizeof(pa_ext_adv_data_2),
+	},
+};
+
+static const struct setup_mgmt_cmd pawr_setup_periodic[] = {
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_PARAMS,
+		.send_param = pa_ext_adv_params,
+		.send_len = sizeof(pa_ext_adv_params),
+	},
+	{
+		.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+		.send_param = pawr_params,
+		.send_len = sizeof(pawr_params),
+	},
+};
+
+static const struct setup_mgmt_cmd pawr_setup_train[] = {
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_PARAMS,
+		.send_param = pa_ext_adv_params,
+		.send_len = sizeof(pa_ext_adv_params),
+	},
+	{
+		.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+		.send_param = pawr_params,
+		.send_len = sizeof(pawr_params),
+	},
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_DATA,
+		.send_param = pa_ext_adv_data,
+		.send_len = sizeof(pa_ext_adv_data),
+	},
+};
+
+static const struct setup_mgmt_cmd pawr_setup_train_slow[] = {
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_PARAMS,
+		.send_param = pa_ext_adv_params,
+		.send_len = sizeof(pa_ext_adv_params),
+	},
+	{
+		.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+		.send_param = pawr_params_slow,
+		.send_len = sizeof(pawr_params_slow),
+	},
+	{
+		.send_opcode = MGMT_OP_ADD_EXT_ADV_DATA,
+		.send_param = pa_ext_adv_data,
+		.send_len = sizeof(pa_ext_adv_data),
+	},
+};
+
+static const struct hci_cmd_data pa_params_hci_cmds[] = {
+	{
+		.opcode = BT_HCI_CMD_LE_SET_PA_PARAMS,
+		.len = sizeof(hci_pa_params),
+		.param = hci_pa_params,
+	},
+	{
+		.opcode = BT_HCI_CMD_LE_SET_PA_ENABLE,
+		.len = sizeof(hci_pa_enable),
+		.param = hci_pa_enable,
+	},
+	{},
+};
+
+static const struct hci_cmd_data pa_params_2_hci_cmds[] = {
+	{
+		.opcode = BT_HCI_CMD_LE_SET_PA_PARAMS,
+		.len = sizeof(hci_pa_params_2),
+		.param = hci_pa_params_2,
+	},
+	{
+		.opcode = BT_HCI_CMD_LE_SET_PA_ENABLE,
+		.len = sizeof(hci_pa_enable_2),
+		.param = hci_pa_enable_2,
+	},
+	{},
+};
+
+static const struct hci_cmd_data pawr_params_hci_cmds[] = {
+	{
+		.opcode = BT_HCI_CMD_LE_SET_PA_PARAMS_V2,
+		.len = sizeof(hci_pa_params_v2),
+		.param = hci_pa_params_v2,
+	},
+	{
+		.opcode = BT_HCI_CMD_LE_SET_PA_ENABLE,
+		.len = sizeof(hci_pa_enable),
+		.param = hci_pa_enable,
+	},
+	{},
+};
+
+/* Both commands have to be sent. Their order is not checked here: the
+ * emulator refuses to remove a set with periodic advertising enabled, which
+ * fails the command.
+ */
+static const struct hci_cmd_data pa_remove_hci_cmds[] = {
+	{
+		.opcode = BT_HCI_CMD_LE_SET_PA_ENABLE,
+		.len = sizeof(hci_pa_disable),
+		.param = hci_pa_disable,
+	},
+	{
+		.opcode = BT_HCI_CMD_LE_REMOVE_ADV_SET,
+		.len = sizeof(hci_pa_remove_set),
+		.param = hci_pa_remove_set,
+	},
+	{},
+};
+
+static const uint8_t hci_pa_disable_2[] = { 0x00, 0x02 };
+
+static const struct hci_cmd_data pa_remove_all_hci_cmds[] = {
+	{
+		.opcode = BT_HCI_CMD_LE_SET_PA_ENABLE,
+		.len = sizeof(hci_pa_disable_2),
+		.param = hci_pa_disable_2,
+	},
+	{
+		.opcode = BT_HCI_CMD_LE_CLEAR_ADV_SETS,
+		.len = 0,
+	},
+	{},
+};
+
+static const struct generic_data pa_params_success = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_instance,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_instance),
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+	.send_param = pa_params,
+	.send_len = sizeof(pa_params),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = pa_instance_1,
+	.expect_len = sizeof(pa_instance_1),
+	.expect_hci_list = pa_params_hci_cmds,
+};
+
+static const struct generic_data pa_params_success_2 = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_instances,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_instances),
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+	.send_param = pa_params_2,
+	.send_len = sizeof(pa_params_2),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = pa_instance_2,
+	.expect_len = sizeof(pa_instance_2),
+	.expect_hci_list = pa_params_2_hci_cmds,
+};
+
+static const struct generic_data pa_params_not_powered = {
+	.setup_settings = settings_le,
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+	.send_param = pa_params,
+	.send_len = sizeof(pa_params),
+	.expect_status = MGMT_STATUS_REJECTED,
+};
+
+static const struct generic_data pa_params_no_instance = {
+	.setup_settings = settings_powered_le,
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+	.send_param = pa_params,
+	.send_len = sizeof(pa_params),
+	.expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data pa_params_connectable = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_instance_conn,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_instance_conn),
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+	.send_param = pa_params,
+	.send_len = sizeof(pa_params),
+	.expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data pa_params_legacy = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_instance_legacy,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_instance_legacy),
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+	.send_param = pa_params,
+	.send_len = sizeof(pa_params),
+	.expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data pa_params_short_interval = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_instance,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_instance),
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+	.send_param = pa_params_short,
+	.send_len = sizeof(pa_params_short),
+	.expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data pa_params_min_above_max = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_instance,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_instance),
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+	.send_param = pa_params_min_max,
+	.send_len = sizeof(pa_params_min_max),
+	.expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+/* For a controller without the feature, with or without an instance */
+static const struct generic_data pa_params_not_supported = {
+	.setup_settings = settings_powered_le,
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+	.send_param = pa_params,
+	.send_len = sizeof(pa_params),
+	.expect_status = MGMT_STATUS_NOT_SUPPORTED,
+};
+
+static const struct generic_data pawr_params_not_supported = {
+	.setup_settings = settings_powered_le,
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+	.send_param = pawr_params,
+	.send_len = sizeof(pawr_params),
+	.expect_status = MGMT_STATUS_NOT_SUPPORTED,
+};
+
+static const struct generic_data pawr_params_success = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_instance,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_instance),
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+	.send_param = pawr_params,
+	.send_len = sizeof(pawr_params),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = pa_instance_1,
+	.expect_len = sizeof(pa_instance_1),
+	.expect_hci_list = pawr_params_hci_cmds,
+};
+
+static const struct generic_data pawr_params_too_many_subevents = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_instance,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_instance),
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+	.send_param = pawr_params_subevents,
+	.send_len = sizeof(pawr_params_subevents),
+	.expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data pa_data_success = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_periodic,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_periodic),
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_DATA,
+	.send_param = pa_data,
+	.send_len = sizeof(pa_data),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = pa_instance_1,
+	.expect_len = sizeof(pa_instance_1),
+	.expect_hci_command = BT_HCI_CMD_LE_SET_PA_DATA,
+	.expect_hci_param = hci_pa_data,
+	.expect_hci_len = sizeof(hci_pa_data),
+};
+
+/* The data can be changed while the train runs */
+static const struct generic_data pa_data_success_running = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_train,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_train),
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_DATA,
+	.send_param = pa_data,
+	.send_len = sizeof(pa_data),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = pa_instance_1,
+	.expect_len = sizeof(pa_instance_1),
+	.expect_hci_command = BT_HCI_CMD_LE_SET_PA_DATA,
+	.expect_hci_param = hci_pa_data,
+	.expect_hci_len = sizeof(hci_pa_data),
+};
+
+static const struct generic_data pa_data_not_periodic = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_instance,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_instance),
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_DATA,
+	.send_param = pa_data,
+	.send_len = sizeof(pa_data),
+	.expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data pa_data_invalid_len = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_periodic,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_periodic),
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_DATA,
+	.send_param = pa_data_len,
+	.send_len = sizeof(pa_data_len),
+	.expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data pa_data_subevents = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pawr_setup_periodic,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pawr_setup_periodic),
+	.send_opcode = MGMT_OP_ADD_PERIODIC_ADV_DATA,
+	.send_param = pa_data,
+	.send_len = sizeof(pa_data),
+	.expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data pa_remove_success = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_train,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_train),
+	.send_opcode = MGMT_OP_REMOVE_ADVERTISING,
+	.send_param = pa_instance_1,
+	.send_len = sizeof(pa_instance_1),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = pa_instance_1,
+	.expect_len = sizeof(pa_instance_1),
+	.expect_alt_ev = MGMT_EV_ADVERTISING_REMOVED,
+	.expect_alt_ev_param = pa_instance_1,
+	.expect_alt_ev_len = sizeof(pa_instance_1),
+	.expect_hci_list = pa_remove_hci_cmds,
+};
+
+static const struct generic_data pawr_remove_success = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pawr_setup_train,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pawr_setup_train),
+	.send_opcode = MGMT_OP_REMOVE_ADVERTISING,
+	.send_param = pa_instance_1,
+	.send_len = sizeof(pa_instance_1),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = pa_instance_1,
+	.expect_len = sizeof(pa_instance_1),
+	.expect_alt_ev = MGMT_EV_ADVERTISING_REMOVED,
+	.expect_alt_ev_param = pa_instance_1,
+	.expect_alt_ev_len = sizeof(pa_instance_1),
+	.expect_hci_list = pa_remove_hci_cmds,
+};
+
+static const struct generic_data pa_remove_all_success = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_trains,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_trains),
+	.send_opcode = MGMT_OP_REMOVE_ADVERTISING,
+	.send_param = pa_instance_all,
+	.send_len = sizeof(pa_instance_all),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = pa_instance_all,
+	.expect_len = sizeof(pa_instance_all),
+	.expect_hci_list = pa_remove_all_hci_cmds,
+};
+
+/* The emulator refuses LE Clear Advertising Sets while periodic advertising
+ * is enabled, which fails Set Powered.
+ */
+static const struct generic_data pawr_power_off = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pawr_setup_train,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pawr_setup_train),
+	.send_opcode = MGMT_OP_SET_POWERED,
+	.send_param = set_powered_off_param,
+	.send_len = sizeof(set_powered_off_param),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_ignore_param = true,
+};
+
+static const struct generic_data pa_subevent_data_no_subevents = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pa_setup_train,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pa_setup_train),
+	.send_opcode = MGMT_OP_SET_PA_SUBEVENT_DATA,
+	.send_param = pa_subevent_data_0,
+	.send_len = sizeof(pa_subevent_data_0),
+	.expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data pa_subevent_data_not_powered = {
+	.setup_settings = settings_le,
+	.send_opcode = MGMT_OP_SET_PA_SUBEVENT_DATA,
+	.send_param = pa_subevent_data_0,
+	.send_len = sizeof(pa_subevent_data_0),
+	.expect_status = MGMT_STATUS_REJECTED,
+};
+
+static const struct generic_data pa_subevent_data_no_entries = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pawr_setup_train,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pawr_setup_train),
+	.send_opcode = MGMT_OP_SET_PA_SUBEVENT_DATA,
+	.send_param = pa_subevent_data_none,
+	.send_len = sizeof(pa_subevent_data_none),
+	.expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data pa_subevent_data_short_entry = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pawr_setup_train,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pawr_setup_train),
+	.send_opcode = MGMT_OP_SET_PA_SUBEVENT_DATA,
+	.send_param = pa_subevent_data_short,
+	.send_len = sizeof(pa_subevent_data_short),
+	.expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data pa_subevent_data_trailing = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pawr_setup_train,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pawr_setup_train),
+	.send_opcode = MGMT_OP_SET_PA_SUBEVENT_DATA,
+	.send_param = pa_subevent_data_long,
+	.send_len = sizeof(pa_subevent_data_long),
+	.expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+/* The controller refuses data it has not asked for yet */
+static const struct generic_data pa_subevent_data_no_request = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pawr_setup_train_slow,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pawr_setup_train_slow),
+	.send_opcode = MGMT_OP_SET_PA_SUBEVENT_DATA,
+	.send_param = pa_subevent_data_0,
+	.send_len = sizeof(pa_subevent_data_0),
+	.expect_status = MGMT_STATUS_BUSY,
+	.expect_hci_command = BT_HCI_CMD_LE_SET_PA_SUBEVENT_DATA,
+	.expect_hci_param = hci_pa_subevent_data_0,
+	.expect_hci_len = sizeof(hci_pa_subevent_data_0),
+};
+
+/* What a test sends when the controller asks for subevent data, and the
+ * status it expects for each command.
+ */
+struct pawr_answer {
+	const void *param;
+	uint16_t len;
+	uint8_t status;
+};
+
+static const uint8_t pawr_data_request_all[] = {
+	0x01, /* instance */
+	0x00, /* subevent_start */
+	0x05, /* subevent_data_count */
+};
+
+static const struct pawr_answer pawr_answers_one[] = {
+	{ pa_subevent_data_0, sizeof(pa_subevent_data_0),
+						MGMT_STATUS_SUCCESS },
+	{ }
+};
+
+/* Both commands are out before the controller answers the first */
+static const struct pawr_answer pawr_answers_two[] = {
+	{ pa_subevent_data_0, sizeof(pa_subevent_data_0),
+						MGMT_STATUS_SUCCESS },
+	{ pa_subevent_data_1, sizeof(pa_subevent_data_1),
+						MGMT_STATUS_SUCCESS },
+	{ }
+};
+
+/* The controller takes the data of a subevent once */
+static const struct pawr_answer pawr_answers_twice[] = {
+	{ pa_subevent_data_0, sizeof(pa_subevent_data_0),
+						MGMT_STATUS_SUCCESS },
+	{ pa_subevent_data_0, sizeof(pa_subevent_data_0),
+						MGMT_STATUS_BUSY },
+	{ pa_subevent_data_1, sizeof(pa_subevent_data_1),
+						MGMT_STATUS_SUCCESS },
+	{ }
+};
+
+/* The train has subevents 0 to 4 */
+static const struct pawr_answer pawr_answers_not_requested[] = {
+	{ pa_subevent_data_5, sizeof(pa_subevent_data_5),
+						MGMT_STATUS_BUSY },
+	{ pa_subevent_data_0, sizeof(pa_subevent_data_0),
+						MGMT_STATUS_SUCCESS },
+	{ }
+};
+
+static const struct generic_data pawr_data_request = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pawr_setup_train,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pawr_setup_train),
+};
+
+static const struct generic_data pawr_answer_success = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pawr_setup_train,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pawr_setup_train),
+	.expect_hci_command = BT_HCI_CMD_LE_SET_PA_SUBEVENT_DATA,
+	.expect_hci_param = hci_pa_subevent_data_0,
+	.expect_hci_len = sizeof(hci_pa_subevent_data_0),
+	.send_param = pawr_answers_one,
+};
+
+static const struct generic_data pawr_answer_two = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pawr_setup_train,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pawr_setup_train),
+	.send_param = pawr_answers_two,
+};
+
+static const struct generic_data pawr_answer_twice = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pawr_setup_train,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pawr_setup_train),
+	.send_param = pawr_answers_twice,
+};
+
+static const struct generic_data pawr_answer_not_requested = {
+	.setup_settings = settings_powered_le,
+	.setup_mgmt_cmd_arr = pawr_setup_train,
+	.setup_mgmt_cmd_arr_size = ARRAY_SIZE(pawr_setup_train),
+	.send_param = pawr_answers_not_requested,
+};
+
+static void pawr_answer_callback(uint8_t status, uint16_t length,
+					const void *param, void *user_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct pawr_answer *answer = user_data;
+
+	tester_print("Set PA Subevent Data: %s (0x%02x)",
+					mgmt_errstr(status), status);
+
+	if (status != answer->status) {
+		tester_warn("Expected status 0x%02x", answer->status);
+		tester_test_failed();
+		return;
+	}
+
+	if (status == MGMT_STATUS_SUCCESS &&
+			(length != sizeof(pa_instance_1) ||
+			memcmp(param, pa_instance_1, length))) {
+		tester_warn("Unexpected return parameters");
+		tester_test_failed();
+		return;
+	}
+
+	test_condition_complete(data);
+}
+
+static void pawr_data_request_callback(uint16_t index, uint16_t length,
+					const void *param, void *user_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct generic_data *test = data->test_data;
+	const struct pawr_answer *answer = test->send_param;
+
+	/* Only the first request of the train is answered */
+	if (!data->mgmt_alt_ev_id)
+		return;
+
+	mgmt_unregister(data->mgmt_alt, data->mgmt_alt_ev_id);
+	data->mgmt_alt_ev_id = 0;
+
+	if (length != sizeof(pawr_data_request_all) ||
+			memcmp(param, pawr_data_request_all, length)) {
+		tester_warn("Unexpected data request:");
+		util_hexdump('>', param, length, print_debug, "");
+		tester_test_failed();
+		return;
+	}
+
+	for (; answer && answer->param; answer++) {
+		test_add_condition(data);
+
+		/* Not mgmt_send(), which waits for the reply to the first
+		 * command before it sends the second.
+		 */
+		mgmt_send_nowait(data->mgmt, MGMT_OP_SET_PA_SUBEVENT_DATA,
+					data->mgmt_index, answer->len,
+					answer->param, pawr_answer_callback,
+					(void *) answer, NULL);
+	}
+
+	test_condition_complete(data);
+}
+
+/* Wait for the first data request of the train and answer it */
+static void test_pawr_answer(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct generic_data *test = data->test_data;
+
+	if (test->expect_hci_command) {
+		hciemu_add_central_post_command_hook(data->hciemu,
+						command_hci_callback, data);
+		test_add_condition(data);
+	}
+
+	data->mgmt_alt_ev_id = mgmt_register(data->mgmt_alt,
+					MGMT_EV_PA_SUBEVENT_DATA_REQUEST,
+					data->mgmt_index,
+					pawr_data_request_callback,
+					NULL, NULL);
+	test_add_condition(data);
+}
+
 static const uint8_t add_advertising_param_empty[] = {
 	0x01,			/* adv instance */
 	0x00, 0x00, 0x00, 0x00,	/* flags: none */
@@ -16211,6 +17151,134 @@ int main(int argc, char *argv[])
 				setup_add_ext_adv_on_off,
 				test_command_generic);
 
+	test_bredrle52("Add Periodic Adv Params - Success",
+				&pa_params_success,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle52("Add Periodic Adv Params - Success (2nd instance)",
+				&pa_params_success_2,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle52("Add Periodic Adv Params - Not powered",
+				&pa_params_not_powered,
+				NULL, test_command_generic);
+
+	test_bredrle52("Add Periodic Adv Params - No instance",
+				&pa_params_no_instance,
+				NULL, test_command_generic);
+
+	test_bredrle52("Add Periodic Adv Params - Connectable",
+				&pa_params_connectable,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle52("Add Periodic Adv Params - Legacy PDUs",
+				&pa_params_legacy,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle52("Add Periodic Adv Params - Interval too short",
+				&pa_params_short_interval,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle52("Add Periodic Adv Params - Min above max interval",
+				&pa_params_min_above_max,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle50("Add Periodic Adv Params - Not supported (5.0)",
+				&pa_params_not_supported,
+				NULL, test_command_generic);
+
+	test_bredrle52("Add Periodic Adv Params - PAwR not supported (5.2)",
+				&pawr_params_not_supported,
+				NULL, test_command_generic);
+
+	test_bredrle60("Add Periodic Adv Params - PAwR Success",
+				&pawr_params_success,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle60("Add Periodic Adv Params - PAwR too many subevents",
+				&pawr_params_too_many_subevents,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle52("Add Periodic Adv Data - Success",
+				&pa_data_success,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle52("Add Periodic Adv Data - Success (train running)",
+				&pa_data_success_running,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle52("Add Periodic Adv Data - Not periodic",
+				&pa_data_not_periodic,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle52("Add Periodic Adv Data - Invalid length",
+				&pa_data_invalid_len,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle60("Add Periodic Adv Data - Instance with subevents",
+				&pa_data_subevents,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle52("Remove Advertising - Periodic Success",
+				&pa_remove_success,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle52("Remove Advertising - Periodic Success (All)",
+				&pa_remove_all_success,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle60("Remove Advertising - PAwR Success",
+				&pawr_remove_success,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle60("Set Powered - Off with PAwR train",
+				&pawr_power_off,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle60("Set PA Subevent Data - No subevents",
+				&pa_subevent_data_no_subevents,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle60("Set PA Subevent Data - Not powered",
+				&pa_subevent_data_not_powered,
+				NULL, test_command_generic);
+
+	test_bredrle60("Set PA Subevent Data - No entries",
+				&pa_subevent_data_no_entries,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle60("Set PA Subevent Data - Entry beyond the packet",
+				&pa_subevent_data_short_entry,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle60("Set PA Subevent Data - Octets after the entries",
+				&pa_subevent_data_trailing,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle60("Set PA Subevent Data - No request",
+				&pa_subevent_data_no_request,
+				setup_command_generic, test_command_generic);
+
+	test_bredrle60("PA Subevent Data Request - Success",
+				&pawr_data_request,
+				setup_command_generic, test_pawr_answer);
+
+	test_bredrle60("Set PA Subevent Data - Success",
+				&pawr_answer_success,
+				setup_command_generic, test_pawr_answer);
+
+	test_bredrle60("Set PA Subevent Data - Success (two commands)",
+				&pawr_answer_two,
+				setup_command_generic, test_pawr_answer);
+
+	test_bredrle60("Set PA Subevent Data - Sent twice",
+				&pawr_answer_twice,
+				setup_command_generic, test_pawr_answer);
+
+	test_bredrle60("Set PA Subevent Data - Subevent not requested",
+				&pawr_answer_not_requested,
+				setup_command_generic, test_pawr_answer);
+
 
 	/* MGMT_OP_SET_DEVICE_ID
 	 * Using Bluetooth SIG for source.
-- 
2.47.3


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

end of thread, other threads:[~2026-12-02 12:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 12:52 [RFC PATCH BlueZ v2 0/9] Periodic advertising and PAwR over MGMT Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 1/9] doc/mgmt: Add PA and PAwR commands and events Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 2/9] lib/mgmt: Add periodic advertising and PAwR definitions Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 3/9] monitor: Decode PA and PAwR MGMT commands and events Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 4/9] client/mgmt: Fix length of byte arrays with empty entries Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 5/9] client/mgmt: Add pa-params, pa-data and pawr-serve commands Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 6/9] monitor: Add PAwR HCI definitions Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 7/9] emulator/btdev: Keep advertising sets with PA enabled Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 8/9] emulator/btdev: Add PAwR advertiser Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 9/9] mgmt-tester: Add periodic advertising and PAwR tests Roland Schober

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