From: Roland Schober <rolandschober1968@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: luiz.dentz@gmail.com, marcel@holtmann.org,
Roland Schober <rolandschober1968@gmail.com>
Subject: [RFC PATCH 4/5] Bluetooth: MGMT: Add Add Periodic Advertising Data command
Date: Fri, 27 Nov 2026 09:53:59 +0100 [thread overview]
Message-ID: <20261127085401.263615-5-rolandschober1968@gmail.com> (raw)
In-Reply-To: <20261127085401.263615-1-rolandschober1968@gmail.com>
Add a MGMT command which sets the data of the periodic advertising
train of an instance made periodic with Add Periodic Advertising
Parameters. It can be sent again to change the data while the train
runs.
The data is limited to what one LE Set Periodic Advertising Data
command takes, as the data of a BIG is. An instance with subevents is
refused: the controller does not allow the command for it.
Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Roland Schober <rolandschober1968@gmail.com>
---
include/net/bluetooth/hci_sync.h | 1 +
include/net/bluetooth/mgmt.h | 14 +++++
net/bluetooth/hci_sync.c | 2 +-
net/bluetooth/mgmt.c | 87 ++++++++++++++++++++++++++++++++
4 files changed, 103 insertions(+), 1 deletion(-)
diff --git a/include/net/bluetooth/hci_sync.h b/include/net/bluetooth/hci_sync.h
index 03d7e267af7c..e6d3d3de482e 100644
--- a/include/net/bluetooth/hci_sync.h
+++ b/include/net/bluetooth/hci_sync.h
@@ -119,6 +119,7 @@ int hci_start_per_adv_sync(struct hci_dev *hdev, u8 instance, u8 sid,
int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance);
int hci_setup_per_adv_instance_sync(struct hci_dev *hdev, u8 instance);
+int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance);
int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk,
u8 instance, bool force);
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 57b9d8d8b57d..a46e87a9152c 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -938,6 +938,20 @@ struct mgmt_rp_add_periodic_adv_params {
__u8 instance;
} __packed;
+/* The data of the periodic advertising train of an instance made periodic
+ * with Add Periodic Advertising Parameters.
+ */
+#define MGMT_OP_ADD_PERIODIC_ADV_DATA 0x005E
+struct mgmt_cp_add_periodic_adv_data {
+ __u8 instance;
+ __u8 data_len;
+ __u8 data[] __counted_by(data_len);
+} __packed;
+#define MGMT_ADD_PERIODIC_ADV_DATA_SIZE 2
+struct mgmt_rp_add_periodic_adv_data {
+ __u8 instance;
+} __packed;
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 3d8327180c6e..05151cf6f413 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -1896,7 +1896,7 @@ static int hci_set_per_adv_params_sync(struct hci_dev *hdev, u8 instance,
sizeof(cp), &cp, HCI_CMD_TIMEOUT);
}
-static int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance)
+int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance)
__context_unsafe(/* conditional locking */)
{
DEFINE_FLEX(struct hci_cp_le_set_per_adv_data, pdu, data, length,
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 2870278d51b0..0f8a58ad1e3c 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -131,6 +131,7 @@ static const u16 mgmt_commands[] = {
MGMT_OP_MESH_SEND_CANCEL,
MGMT_OP_HCI_CMD_SYNC,
MGMT_OP_ADD_PERIODIC_ADV_PARAMS,
+ MGMT_OP_ADD_PERIODIC_ADV_DATA,
};
static const u16 mgmt_events[] = {
@@ -9929,6 +9930,90 @@ static int add_periodic_adv_params(struct sock *sk, struct hci_dev *hdev,
return err;
}
+static void add_periodic_adv_data_complete(struct hci_dev *hdev, void *data,
+ int err)
+{
+ struct mgmt_pending_cmd *cmd = data;
+ struct mgmt_cp_add_periodic_adv_data *cp = cmd->param;
+ struct mgmt_rp_add_periodic_adv_data rp;
+
+ bt_dev_dbg(hdev, "err %d", err);
+
+ if (err) {
+ mgmt_cmd_status(cmd->sk, hdev->id, cmd->opcode,
+ mgmt_status(err));
+ } else {
+ rp.instance = cp->instance;
+ mgmt_cmd_complete(cmd->sk, hdev->id, cmd->opcode,
+ MGMT_STATUS_SUCCESS, &rp, sizeof(rp));
+ }
+
+ mgmt_pending_free(cmd);
+}
+
+static int add_periodic_adv_data_sync(struct hci_dev *hdev, void *data)
+{
+ struct mgmt_pending_cmd *cmd = data;
+ struct mgmt_cp_add_periodic_adv_data *cp = cmd->param;
+
+ return hci_set_per_adv_data_sync(hdev, cp->instance);
+}
+
+static int add_periodic_adv_data(struct sock *sk, struct hci_dev *hdev,
+ void *data, u16 data_len)
+{
+ struct mgmt_cp_add_periodic_adv_data *cp = data;
+ struct mgmt_pending_cmd *cmd;
+ struct adv_info *adv;
+ int err;
+
+ bt_dev_dbg(hdev, "sock %p", sk);
+
+ if (data_len != struct_size(cp, data, cp->data_len) ||
+ cp->data_len > HCI_MAX_PER_AD_LENGTH)
+ return mgmt_cmd_status(sk, hdev->id,
+ MGMT_OP_ADD_PERIODIC_ADV_DATA,
+ MGMT_STATUS_INVALID_PARAMS);
+
+ hci_dev_lock(hdev);
+
+ if (!hdev_is_powered(hdev)) {
+ err = mgmt_cmd_status(sk, hdev->id,
+ MGMT_OP_ADD_PERIODIC_ADV_DATA,
+ MGMT_STATUS_REJECTED);
+ goto unlock;
+ }
+
+ /* The data of an instance with subevents is that of its subevents */
+ adv = hci_find_adv_instance(hdev, cp->instance);
+ if (!adv || !adv->periodic || adv->num_subevents) {
+ err = mgmt_cmd_status(sk, hdev->id,
+ MGMT_OP_ADD_PERIODIC_ADV_DATA,
+ MGMT_STATUS_INVALID_PARAMS);
+ goto unlock;
+ }
+
+ cmd = mgmt_pending_new(sk, MGMT_OP_ADD_PERIODIC_ADV_DATA, hdev, data,
+ data_len);
+ if (!cmd) {
+ err = -ENOMEM;
+ goto unlock;
+ }
+
+ adv->per_adv_data_len = cp->data_len;
+ memcpy(adv->per_adv_data, cp->data, cp->data_len);
+
+ err = hci_cmd_sync_queue(hdev, add_periodic_adv_data_sync, cmd,
+ add_periodic_adv_data_complete);
+ if (err < 0)
+ mgmt_pending_free(cmd);
+
+unlock:
+ hci_dev_unlock(hdev);
+
+ return err;
+}
+
static void remove_advertising_complete(struct hci_dev *hdev, void *data,
int err)
{
@@ -10191,6 +10276,8 @@ static const struct hci_mgmt_handler mgmt_handlers[] = {
{ load_conn_subrate, MGMT_LOAD_CONN_SUBRATE_SIZE,
HCI_MGMT_VAR_LEN },
{ add_periodic_adv_params, MGMT_ADD_PERIODIC_ADV_PARAMS_SIZE },
+ { add_periodic_adv_data, MGMT_ADD_PERIODIC_ADV_DATA_SIZE,
+ HCI_MGMT_VAR_LEN },
};
void mgmt_index_added(struct hci_dev *hdev)
--
2.47.3
next prev parent reply other threads:[~2026-11-27 8:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 8:53 [RFC PATCH 0/5] Bluetooth: Periodic advertising and PAwR over MGMT Roland Schober
2026-11-27 8:53 ` [RFC PATCH 1/5] Bluetooth: hci: Add Periodic Advertising with Responses definitions Roland Schober
2026-11-27 8:53 ` [RFC PATCH 2/5] Bluetooth: hci_sync: Disable periodic advertising before removing a set Roland Schober
2026-11-27 8:53 ` [RFC PATCH 3/5] Bluetooth: MGMT: Add Add Periodic Advertising Parameters command Roland Schober
2026-11-27 8:53 ` Roland Schober [this message]
2026-11-27 8:54 ` [RFC PATCH 5/5] Bluetooth: MGMT: Add PAwR subevent data and response reports Roland Schober
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=20261127085401.263615-5-rolandschober1968@gmail.com \
--to=rolandschober1968@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox