All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roland Schober <rolandschober1968@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Roland Schober <rolandschober1968@gmail.com>
Subject: [PATCH BlueZ v3 8/9] monitor: Add PAwR HCI commands decoding
Date: Thu, 19 Nov 2026 09:16:20 +0100	[thread overview]
Message-ID: <20261119081621.112623-9-rolandschober1968@gmail.com> (raw)
In-Reply-To: <20261119081621.112623-1-rolandschober1968@gmail.com>

Decode the HCI commands introduced by Periodic Advertising with
Responses (PAwR) in Bluetooth 5.4, which so far only had their names
in the opcode table:

 - LE Set Periodic Advertising Subevent Data
 - LE Set Periodic Advertising Response Data
 - LE Set Periodic Sync Subevent
 - LE Extended Create Connection [v2]
 - LE Set Periodic Advertising Parameters [v2]

LE Extended Create Connection [v2] is matched with the events which
complete it like [v1].

The subevent data of LE Set Periodic Advertising Subevent Data is a
list of elements of variable length, each with its own AD structures:

< HCI Command: LE Set Periodic Advertising.. (0x08|0x0082) plen 15
        Handle: 0x00
        Num subevents: 2
        Entry 0
          Subevent: 0 (0x00)
          Response slot start: 0
          Response slot count: 2
          Data length: 5
          Data[5]:
        04 ff 59 00 01                                   ..Y..
        Company: Nordic Semiconductor ASA (89)
          Data[1]:
        01                                               .
        Entry 1
          Subevent: 1 (0x01)
          Response slot start: 0
          Response slot count: 0
          Data length: 0

< HCI Command: LE Set Periodic Advertising.. (0x08|0x0086) plen 12
        Handle: 0x00
        Min interval: 1000.00 msec (0x0320)
        Max interval: 1000.00 msec (0x0320)
        Properties: 0x0000
        Num subevents: 4 (0x04)
        Subevent interval: 100.00 msec (0x50)
        Response slot delay: 6.25 msec (0x05)
        Response slot spacing: 1.000 msec (0x08)
        Num response slots: 32 (0x20)

Assisted-by: Claude:claude-opus-5-5
Assisted-by: Claude:claude-fable-5-2
---
 monitor/bt.h     |  84 ++++++++++++++++
 monitor/packet.c | 247 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 326 insertions(+), 5 deletions(-)

diff --git a/monitor/bt.h b/monitor/bt.h
index 59bc90ccd..b97592afb 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 {
diff --git a/monitor/packet.c b/monitor/packet.c
index fa19139d9..edf09ac10 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -230,6 +230,10 @@ static const struct deferred_data deferred_table[] = {
 	{ BT_HCI_CMD_LE_CREATE_CONN, 0x3e, 0x0a, PENDING_KEY_NONE, 0, 0 },
 	{ BT_HCI_CMD_LE_EXT_CREATE_CONN, 0x3e, 0x01, PENDING_KEY_NONE, 0, 0 },
 	{ BT_HCI_CMD_LE_EXT_CREATE_CONN, 0x3e, 0x0a, PENDING_KEY_NONE, 0, 0 },
+	{ BT_HCI_CMD_LE_EXT_CREATE_CONN_V2, 0x3e, 0x01,
+					PENDING_KEY_NONE, 0, 0 },
+	{ BT_HCI_CMD_LE_EXT_CREATE_CONN_V2, 0x3e, 0x0a,
+					PENDING_KEY_NONE, 0, 0 },
 	{ }
 };
 
@@ -8710,6 +8714,179 @@ static void le_set_pa_params_cmd(uint16_t index, const void *data, uint8_t size)
 	print_pa_properties(cmd->properties);
 }
 
+static void print_pa_subevents(uint8_t num_subevents, uint8_t interval,
+					uint8_t delay, uint8_t spacing)
+{
+	if (!num_subevents)
+		print_field("Num subevents: 0 (no responses) (0x00)");
+	else
+		print_field("Num subevents: %u (0x%2.2x)", num_subevents,
+								num_subevents);
+
+	/* 0x00 is used by the events for trains without responses */
+	if (!interval)
+		print_field("Subevent interval: None (0x00)");
+	else
+		print_field("Subevent interval: %.2f msec (0x%2.2x)",
+						interval * 1.25, interval);
+
+	if (!delay)
+		print_field("Response slot delay: None (0x00)");
+	else
+		print_field("Response slot delay: %.2f msec (0x%2.2x)",
+						delay * 1.25, delay);
+
+	if (!spacing)
+		print_field("Response slot spacing: None (0x00)");
+	else
+		print_field("Response slot spacing: %.3f msec (0x%2.2x)",
+						spacing * 0.125, spacing);
+}
+
+static void le_set_pa_params_v2_cmd(uint16_t index, const void *data,
+							uint8_t size)
+{
+	const struct bt_hci_cmd_le_set_pa_params_v2 *cmd = data;
+
+	/* The v2 command starts with the parameters of the v1 command */
+	le_set_pa_params_cmd(index, data, size);
+	print_pa_subevents(cmd->num_subevents, cmd->subevent_interval,
+				cmd->response_slot_delay,
+				cmd->response_slot_spacing);
+	print_field("Num response slots: %u (0x%2.2x)",
+				cmd->num_response_slots,
+				cmd->num_response_slots);
+}
+
+static void le_set_pa_params_v2_rsp(uint16_t index, const void *data,
+							uint8_t size)
+{
+	const struct bt_hci_rsp_le_set_pa_params_v2 *rsp = data;
+
+	print_status(rsp->status);
+	print_field("Handle: 0x%2.2x", rsp->handle);
+}
+
+static void le_set_pa_subevent_data_cmd(uint16_t index, const void *data,
+							uint8_t size)
+{
+	struct iovec iov = { .iov_base = (void *) data, .iov_len = size };
+	const struct bt_hci_cmd_le_set_pa_subevent_data *cmd;
+	const struct bt_hci_le_pa_subevent_data *se;
+	uint8_t i;
+
+	cmd = util_iov_pull_mem(&iov, sizeof(*cmd));
+	if (!cmd)
+		return;
+
+	print_field("Handle: 0x%2.2x", cmd->handle);
+	print_field("Num subevents: %u", cmd->num_subevents);
+
+	for (i = 0; i < cmd->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 < cmd->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);
+	}
+}
+
+static void le_set_pa_subevent_data_rsp(uint16_t index, const void *data,
+							uint8_t size)
+{
+	const struct bt_hci_rsp_le_set_pa_subevent_data *rsp = data;
+
+	print_status(rsp->status);
+	print_field("Handle: 0x%2.2x", rsp->handle);
+}
+
+static void le_set_pa_response_data_cmd(uint16_t index, const void *data,
+							uint8_t size)
+{
+	const struct bt_hci_cmd_le_set_pa_response_data *cmd = data;
+
+	print_field("Sync handle: %d", le16_to_cpu(cmd->sync_handle));
+	print_field("Request event: %u (0x%4.4x)",
+					le16_to_cpu(cmd->request_event),
+					le16_to_cpu(cmd->request_event));
+	print_field("Request subevent: %u (0x%2.2x)", cmd->request_subevent,
+						cmd->request_subevent);
+	print_field("Response subevent: %u (0x%2.2x)", cmd->response_subevent,
+						cmd->response_subevent);
+	print_field("Response slot: %u (0x%2.2x)", cmd->response_slot,
+						cmd->response_slot);
+	print_field("Data length: %u", cmd->data_len);
+
+	if (cmd->data_len != size - sizeof(*cmd)) {
+		print_text(COLOR_ERROR, "invalid data length");
+		packet_hexdump(cmd->data, size - sizeof(*cmd));
+		return;
+	}
+
+	print_eir("Data", cmd->data, cmd->data_len, true);
+}
+
+static void le_set_pa_response_data_rsp(uint16_t index, const void *data,
+							uint8_t size)
+{
+	const struct bt_hci_rsp_le_set_pa_response_data *rsp = data;
+
+	print_status(rsp->status);
+	print_field("Sync handle: %d", le16_to_cpu(rsp->sync_handle));
+}
+
+static void le_set_pa_sync_subevent_cmd(uint16_t index, const void *data,
+							uint8_t size)
+{
+	const struct bt_hci_cmd_le_set_pa_sync_subevent *cmd = data;
+	uint8_t i;
+
+	print_field("Sync handle: %d", le16_to_cpu(cmd->sync_handle));
+	print_pa_properties(cmd->properties);
+	print_field("Num subevents: %u", cmd->num_subevents);
+
+	size -= sizeof(*cmd);
+
+	for (i = 0; i < cmd->num_subevents && i < size; i++)
+		print_field("  Subevent: %u (0x%2.2x)", cmd->subevents[i],
+							cmd->subevents[i]);
+
+	if (cmd->num_subevents != size)
+		print_text(COLOR_ERROR, "  invalid number of subevents");
+
+	if (size > cmd->num_subevents)
+		print_hex_field("  Data", cmd->subevents + cmd->num_subevents,
+						size - cmd->num_subevents);
+}
+
+static void le_set_pa_sync_subevent_rsp(uint16_t index, const void *data,
+							uint8_t size)
+{
+	const struct bt_hci_rsp_le_set_pa_sync_subevent *rsp = data;
+
+	print_status(rsp->status);
+	print_field("Sync handle: %d", le16_to_cpu(rsp->sync_handle));
+}
+
 static void le_set_pa_data_cmd(uint16_t index, const void *data, uint8_t size)
 {
 	const struct bt_hci_cmd_le_set_pa_data *cmd = data;
@@ -8902,6 +9079,28 @@ static void le_ext_create_conn_cmd(uint16_t index, const void *data,
 	print_ext_conn_phys(cmd->data, size - sizeof(*cmd), cmd->phys);
 }
 
+static void le_ext_create_conn_v2_cmd(uint16_t index, const void *data,
+							uint8_t size)
+{
+	const struct bt_hci_cmd_le_ext_create_conn_v2 *cmd = data;
+
+	if (cmd->adv_handle == 0xff)
+		print_field("Advertising handle: No Advertising Handle (0xff)");
+	else
+		print_field("Advertising handle: %u (0x%2.2x)",
+					cmd->adv_handle, cmd->adv_handle);
+
+	if (cmd->subevent == 0xff)
+		print_field("Subevent: No subevent (0xff)");
+	else
+		print_field("Subevent: %u (0x%2.2x)", cmd->subevent,
+							cmd->subevent);
+
+	/* The remaining parameters are the ones of the v1 command */
+	le_ext_create_conn_cmd(index, &cmd->filter_policy,
+			size - sizeof(cmd->adv_handle) - sizeof(cmd->subevent));
+}
+
 static const struct bitfield_data create_sync_cte_type[] = {
 	{  0, "Do not sync to packets with AoA CTE"	},
 	{  1, "Do not sync to packets with AoD CTE 1us"	},
@@ -12019,11 +12218,49 @@ static const struct opcode_data opcode_table[] = {
 	{ 0x207f, 370, "LE Set Extended Advertising Parameters [v2]" },
 	{ 0x2080, 371, "LE Set Decision Data" },
 	{ 0x2081, 372, "LE Set Decision Instructions" },
-	{ 0x2082, 373, "LE Set Periodic Advertising Subevent Data" },
-	{ 0x2083, 374, "LE Set Periodic Advertising Response Data" },
-	{ 0x2084, 375, "LE Set Periodic Sync Subevent" },
-	{ 0x2085, 376, "LE Extended Create Connection [v2]" },
-	{ 0x2086, 377, "LE Set Periodic Advertising Parameters [v2]" },
+	{ BT_HCI_CMD_LE_SET_PA_SUBEVENT_DATA,
+			BT_HCI_BIT_LE_SET_PA_SUBEVENT_DATA,
+			"LE Set Periodic Advertising Subevent Data",
+			le_set_pa_subevent_data_cmd,
+			sizeof(struct bt_hci_cmd_le_set_pa_subevent_data),
+			false,
+			le_set_pa_subevent_data_rsp,
+			sizeof(struct bt_hci_rsp_le_set_pa_subevent_data),
+			true },
+	{ BT_HCI_CMD_LE_SET_PA_RESPONSE_DATA,
+			BT_HCI_BIT_LE_SET_PA_RESPONSE_DATA,
+			"LE Set Periodic Advertising Response Data",
+			le_set_pa_response_data_cmd,
+			sizeof(struct bt_hci_cmd_le_set_pa_response_data),
+			false,
+			le_set_pa_response_data_rsp,
+			sizeof(struct bt_hci_rsp_le_set_pa_response_data),
+			true },
+	{ BT_HCI_CMD_LE_SET_PA_SYNC_SUBEVENT,
+			BT_HCI_BIT_LE_SET_PA_SYNC_SUBEVENT,
+			"LE Set Periodic Sync Subevent",
+			le_set_pa_sync_subevent_cmd,
+			sizeof(struct bt_hci_cmd_le_set_pa_sync_subevent),
+			false,
+			le_set_pa_sync_subevent_rsp,
+			sizeof(struct bt_hci_rsp_le_set_pa_sync_subevent),
+			true },
+	{ BT_HCI_CMD_LE_EXT_CREATE_CONN_V2,
+			BT_HCI_BIT_LE_EXT_CREATE_CONN_V2,
+			"LE Extended Create Connection [v2]",
+			le_ext_create_conn_v2_cmd,
+			sizeof(struct bt_hci_cmd_le_ext_create_conn_v2),
+			false,
+			status_rsp, 1, true },
+	{ BT_HCI_CMD_LE_SET_PA_PARAMS_V2,
+			BT_HCI_BIT_LE_SET_PA_PARAMS_V2,
+			"LE Set Periodic Advertising Parameters [v2]",
+			le_set_pa_params_v2_cmd,
+			sizeof(struct bt_hci_cmd_le_set_pa_params_v2),
+			true,
+			le_set_pa_params_v2_rsp,
+			sizeof(struct bt_hci_rsp_le_set_pa_params_v2),
+			true },
 	{ BT_HCI_CMD_LE_READ_ALL_LOCAL_FEATURES,
 			BT_HCI_BIT_LE_READ_ALL_LOCAL_FEATURES,
 			"LE Read All Local Features",
-- 
2.47.3


  parent reply	other threads:[~2026-11-19  8:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  8:16 [PATCH BlueZ v3 0/9] monitor: Decode Periodic Advertising with Responses Roland Schober
2026-11-19  8:16 ` [PATCH BlueZ v3 1/9] monitor: Fix handle decoding of status_handle_rsp Roland Schober
2026-11-19  9:53   ` monitor: Decode Periodic Advertising with Responses bluez.test.bot
2026-11-19  8:16 ` [PATCH BlueZ v3 2/9] monitor: Fix data length of LE PA Report decoding Roland Schober
2026-11-19  8:16 ` [PATCH BlueZ v3 3/9] monitor: Fix PHY decoding of LE Ext Create Connection Roland Schober
2026-11-19  8:16 ` [PATCH BlueZ v3 4/9] monitor: Fix advertising handle of LE PA commands Roland Schober
2026-11-19  8:16 ` [PATCH BlueZ v3 5/9] monitor: Fix TX power and CTE Type of LE PA Report Roland Schober
2026-11-19  8:16 ` [PATCH BlueZ v3 6/9] monitor: Fix LE PAST Received decoding Roland Schober
2026-11-19  8:16 ` [PATCH BlueZ v3 7/9] monitor: Split LE PA Report decoding into helpers Roland Schober
2026-11-19  8:16 ` Roland Schober [this message]
2026-11-19  8:16 ` [PATCH BlueZ v3 9/9] monitor: Add PAwR HCI events decoding Roland Schober
2026-11-19 16:18 ` [PATCH BlueZ v3 0/9] monitor: Decode Periodic Advertising with Responses Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119081621.112623-9-rolandschober1968@gmail.com \
    --to=rolandschober1968@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.