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

This is the user space side of the kernel RFC
"[RFC PATCH v2 0/6] 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 interface is the one of v1. The kernel
series is at v2 for one more fix: the train of an instance whose
advertising timed out went on.

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.

Patches 4 and 5 fix how btmgmt reads a byte array, which the new
commands use: the length with empty entries, and negative values.
Patch 6 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 7 to 11 are the emulator:

 - Patch 7 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 8 gives the handlers which patches 10 and 11 extend a check
   of the command length.
 - Patch 9 keeps the advertising set when the duration of its
   advertising ends. The emulator freed it, also with periodic
   advertising enabled on it.
 - Patch 10 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 11 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 12 adds 33 mgmt-tester cases. They need the kernel series; on a
kernel without it they fail. The case with a timeout needs v2 of it.

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.

v3:
 - Emulator: check the length of LE Set Periodic Advertising
   Parameters [v2] (Copilot), and of the commands whose handlers the
   series extends (new patch 8). The handlers were then fed truncated,
   extended and random commands under AddressSanitizer.
 - btmgmt pawr-serve: tell the shell that the command stays running,
   so that the lines of a script after it are run (Copilot). Print a
   response report which has no responses.
 - btmgmt: refuse negative values in a byte array (new patch 5).
 - Emulator: LE Set Periodic Advertising Enable checks its handle. It
   is refused for a set which does not exist, and for a set other than
   the one with the parameters.
 - Emulator: keep the advertising set when the duration of its
   advertising ends (new patch 9). With the check above, a train on a
   set which was freed that way could not be disabled any more.
 - doc/mgmt-protocol.rst: subevent data which was not requested fails
   with Busy.
 - mgmt-tester: new case for an instance with a timeout and a train.
   The kernel has to disable the train and remove the set when the
   advertising of the set ends, which v2 of the kernel series does.
 - mgmt-tester: the "Sent twice" case uses an interval of 2 s, so the
   second answer is out before the next request. The "too many
   subevents" case breaks no other rule than the number.
 - Rebased.

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 (now 1, 3, 10 and 11).
 - Rebased.

Roland Schober (12):
  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: Refuse negative values in byte arrays
  client/mgmt: Add pa-params, pa-data and pawr-serve commands
  monitor: Add PAwR HCI definitions
  emulator/btdev: Check the length of PA commands
  emulator/btdev: Keep the advertising set after a timeout
  emulator/btdev: Keep advertising sets with PA enabled
  emulator/btdev: Add PAwR advertiser
  mgmt-tester: Add periodic advertising and PAwR tests

 client/mgmt.c             |  384 ++++++++++++-
 doc/bluetoothctl-mgmt.rst |   51 ++
 doc/mgmt-protocol.rst     |  210 +++++++
 emulator/btdev.c          |  337 ++++++++++-
 lib/bluetooth/mgmt.h      |   74 +++
 monitor/bt.h              |  174 ++++++
 monitor/packet.c          |  204 +++++++
 tools/mgmt-tester.c       | 1119 +++++++++++++++++++++++++++++++++++++
 8 files changed, 2544 insertions(+), 9 deletions(-)


base-commit: 736384fcdc45dc343c8109317510f4e2a31bd7fb
-- 
2.47.3


^ permalink raw reply	[flat|nested] 15+ messages in thread
* [RFC PATCH BlueZ 1/9] doc/mgmt: Add periodic advertising and PAwR commands and events
@ 2026-11-27  8:55 Roland Schober
  2026-11-27 15:37 ` Periodic advertising and PAwR over MGMT bluez.test.bot
  0 siblings, 1 reply; 15+ messages in thread
From: Roland Schober @ 2026-11-27  8:55 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..899b5c6f5 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:
+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] 15+ messages in thread

end of thread, other threads:[~2026-12-04  8:24 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 22:15 [RFC PATCH BlueZ v3 00/12] Periodic advertising and PAwR over MGMT Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 01/12] doc/mgmt: Add PA and PAwR commands and events Roland Schober
2026-12-04  8:23   ` Periodic advertising and PAwR over MGMT bluez.test.bot
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 02/12] lib/mgmt: Add periodic advertising and PAwR definitions Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 03/12] monitor: Decode PA and PAwR MGMT commands and events Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 04/12] client/mgmt: Fix length of byte arrays with empty entries Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 05/12] client/mgmt: Refuse negative values in byte arrays Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 06/12] client/mgmt: Add pa-params, pa-data and pawr-serve commands Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 07/12] monitor: Add PAwR HCI definitions Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 08/12] emulator/btdev: Check the length of PA commands Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 09/12] emulator/btdev: Keep the advertising set after a timeout Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 10/12] emulator/btdev: Keep advertising sets with PA enabled Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 11/12] emulator/btdev: Add PAwR advertiser Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 12/12] mgmt-tester: Add periodic advertising and PAwR tests Roland Schober
  -- strict thread matches above, loose matches on Subject: below --
2026-11-27  8:55 [RFC PATCH BlueZ 1/9] doc/mgmt: Add periodic advertising and PAwR commands and events Roland Schober
2026-11-27 15:37 ` Periodic advertising and PAwR over MGMT bluez.test.bot

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