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

Hi Luiz,

v2 of the RFC for periodic advertising and the advertiser side of
Periodic Advertising with Responses (PAwR) over MGMT. The interface
is the one of v1, and the questions on it are still open; v2 fixes
one more case in the kernel, which the review of the BlueZ series
brought up, and is rebased onto bluetooth-next.

Changes in v2:
 - New patch 3: an instance with a timeout and periodic advertising.
   When the timeout ends the controller stops the advertising of the
   set, and the kernel freed its instance. The periodic advertising
   went on in the controller, and nothing stopped it any more. The
   kernel now disables it and removes the set.
 - Patch 2 is the fix I sent on its own after v1 ("Bluetooth:
   hci_sync: Disable PA before removing an advertising set"), with
   that commit message. The code is the one of v1.
 - Rebased onto bluetooth-next. Patches 1 and 4 to 6 are unchanged.

v1: "[RFC PATCH 0/5] Bluetooth: Periodic advertising and PAwR over
MGMT"

The interface (patches 4 to 6):

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

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

Questions:

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

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

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

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

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

6. New in v2: an instance with a timeout which is periodic is removed
   as a whole when the timeout ends, train included (patch 3). The
   other way would be to refuse periodic advertising parameters for an
   instance with a timeout. Is removing it what you would expect?

Not in this series:

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

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

Patches 2 and 3 are needed by the others but stand on their own.
Patch 2: the controller refuses to remove an advertising set while
periodic advertising is enabled on it. Patch 3 changes nothing for an
instance without periodic advertising.

Tested in two ways.

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

With a real controller, in QEMU: the Nordic SoftDevice Controller on a
simulated nRF52 (BabbleSim), with Zephyr's periodic_sync_rsp sample as
the responder. Plain periodic advertising: the train starts, its data
is set and changed while it runs, the instance is removed. PAwR: the
train starts, the responder is connected and synchronised by PAST,
95 data requests in 8 s are all answered in time and the responses
arrive. An instance with a timeout and a PAwR train: when the timeout
ends the controller sends LE Advertising Set Terminated and goes on
with the train. Without patch 3 the data requests continue, and Add
Periodic Advertising Parameters for the instance fails with Busy
when it is added again. With it the train is disabled, the set is
removed, and the instance can be added again. An earlier state of the
PAwR patches, ported to 6.6, runs the PAwR exchange on an i.MX93
board.

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

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

Roland Schober (6):
  Bluetooth: hci: Add Periodic Advertising with Responses definitions
  Bluetooth: hci_sync: Disable PA before removing an advertising set
  Bluetooth: hci_event: Stop PA when an advertising set times out
  Bluetooth: MGMT: Add Add Periodic Advertising Parameters command
  Bluetooth: MGMT: Add Add Periodic Advertising Data command
  Bluetooth: MGMT: Add PAwR subevent data and response reports

 include/net/bluetooth/hci.h      |  59 +++++
 include/net/bluetooth/hci_core.h |  20 ++
 include/net/bluetooth/hci_sync.h |   2 +
 include/net/bluetooth/mgmt.h     |  89 +++++++
 net/bluetooth/hci_event.c        | 115 +++++++++-
 net/bluetooth/hci_sync.c         | 104 ++++++++-
 net/bluetooth/mgmt.c             | 382 +++++++++++++++++++++++++++++++
 7 files changed, 767 insertions(+), 4 deletions(-)


base-commit: 738af1958d2e7205008ca818352199ae8e454509
-- 
2.47.3


^ permalink raw reply	[flat|nested] 9+ messages in thread
* [RFC PATCH 1/5] Bluetooth: hci: Add Periodic Advertising with Responses definitions
@ 2026-11-27  8:53 Roland Schober
  2026-11-27 13:58 ` Bluetooth: Periodic advertising and PAwR over MGMT bluez.test.bot
  0 siblings, 1 reply; 9+ messages in thread
From: Roland Schober @ 2026-11-27  8:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, marcel, Roland Schober

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

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

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

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


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

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

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 22:13 [RFC PATCH v2 0/6] Bluetooth: Periodic advertising and PAwR over MGMT Roland Schober
2026-12-03 22:14 ` [RFC PATCH v2 1/6] Bluetooth: hci: Add Periodic Advertising with Responses definitions Roland Schober
2026-12-04  2:11   ` Bluetooth: Periodic advertising and PAwR over MGMT bluez.test.bot
2026-12-03 22:14 ` [RFC PATCH v2 2/6] Bluetooth: hci_sync: Disable PA before removing an advertising set Roland Schober
2026-12-03 22:14 ` [RFC PATCH v2 3/6] Bluetooth: hci_event: Stop PA when an advertising set times out Roland Schober
2026-12-03 22:14 ` [RFC PATCH v2 4/6] Bluetooth: MGMT: Add Add Periodic Advertising Parameters command Roland Schober
2026-12-03 22:14 ` [RFC PATCH v2 5/6] Bluetooth: MGMT: Add Add Periodic Advertising Data command Roland Schober
2026-12-03 22:14 ` [RFC PATCH v2 6/6] Bluetooth: MGMT: Add PAwR subevent data and response reports Roland Schober
  -- strict thread matches above, loose matches on Subject: below --
2026-11-27  8:53 [RFC PATCH 1/5] Bluetooth: hci: Add Periodic Advertising with Responses definitions Roland Schober
2026-11-27 13:58 ` Bluetooth: 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